当我用jest和酶测试我的反应项目时,我遇到了这个问题, `TypeError:symbol不是函数
44 | test('PROVA', () => {
> 46 | const wrapper = mount(<I18nextProvider i18n={i18n}><MemoryRouter><LoggedSearch t={(k) => 'translate hardcoded'} userData={Artist}/></MemoryRouter></I18nextProvider>,{context});
| ^
47 | console.log(wrapper.debug());
48 | wrapper.find('#ButtonSearch').simulate('click', { preventDefault() {} });
49 | expect(true).toBe(true)
at setValueForProperty (../node_modules/react-dom/cjs/react-dom.development.js:2909:46)
现在这是我的测试
test('PROVA', () => {
//const wrapper = mount(<LoggedSearch t={key=>key} userData={Artist}/>);
const wrapper = mount(<I18nextProvider i18n={i18n}><MemoryRouter><LoggedSearch t={(k) => 'translate hardcoded'} userData={Artist}/></MemoryRouter></I18nextProvider>,{context});
console.log(wrapper.debug());
wrapper.find('#ButtonSearch').simulate('click', { preventDefault() {} });
expect(true).toBe(true)
});
在<LoggedSearch/>
中,组件将使用指定的导出导出,并在我的测试文件中导入import {LoggedSearch} from "../components/LoggedSearch";
因此组件应该是纯粹的进口,没有像i18n这样的装饰吗? 。我不明白为什么测试失败并出现此错误TypeError: symbol is not a function
我认为这是一个i18n问题,因为当我使用浅而不是mount时,它可以工作,但我不能用浅层测试功能。感谢
答案 0 :(得分:3)
我遇到了同样的问题,这是由于通过webpack导入了图像。我通过创建一个fileMock.js来解决此问题:
[yield x for x in [a, b, c]]
然后以开玩笑的配置:
c
此处有更多详细信息: https://jestjs.io/docs/en/webpack
答案 1 :(得分:0)
我不确定这是否是您的确切问题,但这可能是由于您通过webpack导入图像,导入的方式引起的。可能类似于this问题。