【发布时间】:2017-03-15 17:00:26
【问题描述】:
有没有办法忽略 Jest 的错误?
我在导入包时收到错误消息,我想忽略该错误,以便测试我的其余代码。
【问题讨论】:
标签: react-native jestjs
有没有办法忽略 Jest 的错误?
我在导入包时收到错误消息,我想忽略该错误,以便测试我的其余代码。
【问题讨论】:
标签: react-native jestjs
您应该将 transformIgnorePatterns 添加到您的 package.json:
"jest": {
"preset": "react-native",
"transformIgnorePatterns": [
"/node_modules/(?!react-native|*put library here*)"
]
},
【讨论】:
TypeError: Cannot read property 'style' of undefined at Object.<anonymous> (node_modules/react-native-snap-carousel/index.js:472:842) 运行应用程序时不会弹出此错误
<Provider store={store}> <Guides {...props} /> </Provider>和我的组件Guides导入包
react-native-snap-carousel 提出问题?
在你的测试文件中添加这个玩笑test或describe
console.error = jest.fn()
基本上它会让 jest 模拟 console.error 函数,所以它会通过测试。
【讨论】:
在我的 jestsetup.js 中,请添加
console.error = message => {
// throw new Error(message);
};
我的 jestsetup.js 文件
// Make Enzyme functions available in all test files without importing
import { shallow, render, mount } from 'enzyme';
global.shallow = shallow;
global.render = render;
global.mount = mount;
// Fail tests on any warning
console.error = message => {
// throw new Error(message);
};
【讨论】:
只需使用test.skipit.skip、xit 或xtest 而不是test 或it 即可跳过特定测试。看看docs。
【讨论】: