下面是一个非常简单的规范文件,用于单元测试TypeScript + React应用程序:
import * as React from "react"; // COMMON
import * as chai from "chai"; // COMMON
import * as chaiEnzyme from "chai-enzyme" // COMMON
import * as sinon from "sinon"; // COMMON
import * as sinonChai from "sinon-chai"; // COMMON
import { expect } from "chai"; // COMMON
import { shallow } from "enzyme"; // COMMON
import Hello from "./Hello";
describe("Hello", () => {
chai.use(chaiEnzyme()); // COMMON
chai.use(sinonChai); // COMMON
let hello = shallow(<Hello name="Willson" />);
it("should render correctly", () => {
expect(hello).to.have.tagName("div");
});
it("should have correct prop values", () => {
expect(hello).to.have.text("Hello, Willson");
});
});我看到自己在使用行,每个规范文件都使用// COMMON。在我的所有文件上,默认情况下,是否有一种与/Spec\.(ts|tsx)/**?**匹配的TypeScript方法:TypeScript
发布于 2017-01-19 16:08:15
你可以做一件事来稍微减轻这个问题。
首先像这样创建您的common.ts:
//Collect and re-export all of your COMMON imports
import * as React from "react";
export {React};
import * as ReactDOM from 'react-dom';
export {ReactDOM};
//More import/exports goes here然后,在您的spec文件中,只需要有一个导入:
import * as Common from './common';稍后在spec文件中,您使用它们的方式如下:
private static childContextTypes =
{
extender: Common.React.PropTypes.object,
form: Common.React.PropTypes.object
}希望这能有所帮助。
https://stackoverflow.com/questions/41744239
复制相似问题