使用React Native,jest和酶,我甚至无法检查浅层渲染组件的值,更不用说对它运行测试断言了 .
Enzyme和jest适用于其他测试文件 .
我的控制台中没有发生任何错误的日志输出 .
import React from 'react';
import { shallow } from 'enzyme';
import { SomeComponent } from '../SomeComponent';
describe('SomeComponent', () => {
it('renders', () => {
const props = { name: 'hey' }
const shallowWrap = shallow(<SomeComponent {...props} />);
console.log(shallowWrap) // this wont even log
expect(shallowWrap).toMatchSnapshot();
});
});
1 回答
在我的组件变浅处缠绕try / catch并记录错误表明我在
SomeComponent
的渲染函数中抛出了一个错误 .修复了该错误的原因并且现在工作正常 .