如何解决开玩笑的测试:当整个react应用都位于打字稿模块中时,如何导入react组件
我将我的整个项目放在一个模块中,现在我想用测试覆盖这个项目,但是我不知道如何导入道具,因此,我可以访问想要测试或导入“渲染”的所需组件。来自测试库/反应”。 我的组件看起来像这样:
MyComponent.tsx
module MainModule {
interface Props extends ReactTabComponentProps {
}
interface State extends ReactComponentState {
}
export class MyComponent extends ReactTabComponent<Props,State> {
constructor(props: Props) {
super(props);
this.state = {
};
}
setTitle = () => {
this.props.tab.setTitle(
<span>
<Icon name="calculator" fixedWidth />
MainComponent
</span>
);
}
render() {
return (
);
}
}
}
我无法弄清楚如何在测试中访问上述组件。我的测试如下:
MyComponent.test.tsx
module MainModule {
import { MainComponent } from '../Main/components/MainComponent';
import { render } from '@testing-library/react';
describe("mainComponentTest",() => {
it("should renders correctly",async () => {
});
});
}
这样,我会得到TS错误,错误:名称空间中的导入声明无法引用模块。
如果我从测试中删除模块或在模块外部写入导入内容,则会收到错误消息:
(TS)Cannot compile modules using option 'outFile' unless the '--module'flag is 'amd' or 'system'.
并且我不想从ts.config文件中删除outFile选项
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。