问题描述
我刚刚遇到了一个很奇怪的问题,在 jest 文档中没有定义。该文档 (DOM) 来自其他源文件。我尝试在测试文件的顶部使用dockblock 符号/注释。
/**
* @jest-environment jsdom
*/
不幸的是没有成功。
我遇到了这个错误:
1 | var AppSettings = {
> 2 | mainPath: document.getElementsByTagName("base")[0].href
知道为什么会这样吗?我的 jsconfig 测试环境也设置为 jsdom。似乎没什么帮助...
这是jest测试的结构:
const mockProps =
{
translate: translate,service: service1,httpService: http,toaster: toastr
};
describe("Test information",() => {
let component;
beforeEach(() => {
component = shallow(<information {...mockProps}/>);
});
it("should render",() => {
expect(component).tobedefined();
});
});
我的信息组件使用 mainpath 变量从服务器获取数据。任何帮助表示赞赏。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)