【发布时间】:2018-11-16 11:28:47
【问题描述】:
当我用 jest 和酵素测试我的反应项目时,我遇到了这个问题, `TypeError: 符号不是函数
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 问题,因为当我使用浅层而不是挂载时它可以工作,但我无法用浅层测试函数。谢谢
【问题讨论】:
标签: reactjs testing internationalization jestjs enzyme