In React Native how can I test my components with Shallow Rendering?

后端 未结 2 1820
悲&欢浪女
悲&欢浪女 2021-02-07 03:17

For React, I use Shallow Rendering techniques for unit testing my React components. Can I do something similar in React Native?

I\'ve followed the instructions to set

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-07 03:54

    You can do this without using enzyme, just use Shallow Renderer from react-test-renderer.

    import ShallowRenderer from 'react-test-renderer/shallow';
    
    it('renders', () => {
      const renderer = new ShallowRenderer();
      renderer.render();
    
      expect(wrapper).toMatchSnapshot();
    });
    

提交回复
热议问题