【发布时间】:2016-03-22 19:55:28
【问题描述】:
请在 github 上查看我的demo project。
在我的react-tfractal/tests/component/tfractal.spec.tsx 测试中:
import * as React from 'react';
import * as ReactTestUtils from 'react-addons-test-utils';
import {expect} from 'chai';
import {Tfractal} from '../../src/tfractal';
var R = React;
describe('tfractal', function () {
it('renders', function () {
var tfractal = ReactTestUtils.renderIntoDocument(<Tfractal />);
expect(tfractal).exist;
});
});
React import 从未使用过,但react-addons-test-utils 需要(如果没有 React 导入,我会收到错误消息“React 未定义”)。问题是:没有线
var R = React;
此导入已被 typescript 编译器删除。
import 'react'
不会被删除但不起作用(同样的错误消息“React 未定义”)。
如何在不创建虚拟变量的情况下解决它?
运行
npm install
tsd install
npm run test
检查。
【问题讨论】:
标签: javascript unit-testing import reactjs typescript