Mar*_*rio 3 testing internationalization reactjs jestjs enzyme
当我用笑话和酶测试我的反应项目时,我遇到了这个问题,`TypeError: symbol is not a function
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)
Run Code Online (Sandbox Code Playgroud)
现在这是我的测试
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)
});
Run Code Online (Sandbox Code Playgroud)
在<LoggedSearch/>
组件中使用命名导出导出并在我的测试文件中导入import {LoggedSearch} from "../components/LoggedSearch";
所以组件应该像 i18n 一样没有装饰地导入,对吗?. 我不明白为什么测试失败并出现此错误TypeError: symbol is not a function
我认为这是一个 i18n 问题,因为当我使用浅而不是安装时,它可以工作,但我无法使用浅来测试功能。谢谢
小智 5
我有同样的问题,这是由于通过 webpack 导入的图像。我通过创建一个 fileMock.js 解决了这个问题:
module.exports = 'test-file-stub';
Run Code Online (Sandbox Code Playgroud)
然后在开玩笑的配置中:
"moduleNameMapper": {
"\\.(css|scss)$": "identity-obj-proxy",
"\\.(png|svg|pdf|jpg|jpeg)$": "<rootDir>/__mocks__/fileMock.js"
}
Run Code Online (Sandbox Code Playgroud)
更多细节在这里:https : //jestjs.io/docs/en/webpack
归档时间: |
|
查看次数: |
4097 次 |
最近记录: |