对于
React,我使用
Shallow Rendering技术对我的React组件进行单元测试。我可以在
React Native做类似的事情吗?
我有followed the instructions to set up Jest,但找不到有关测试我的组件的任何文档。我想用React Native做完整的TDD,与React一样。
我想
enzyme是你要找的。
它为您提供了一个浅层功能,允许您进行浅比较(如您所愿)。
酶可以与所有受欢迎的测试运动员一起使用(如摩卡,杰斯,业力等)。完整列表可以找到on the library’s github page。
例:
- import {shallow} from 'enzyme';
- describe('<MyComponent />',() => {
- it('should render three <Foo /> components',() => {
- const wrapper = shallow(<MyComponent />);
- expect(wrapper.find(Foo)).to.have.length(3);
- });
- });
为了进一步阅读,您可以看看酶的Shallow Rendering API或docs。