Nested components testing with Enzyme inside of React & Redux

后端 未结 6 1107
甜味超标
甜味超标 2020-12-24 05:55

I have a component SampleComponent that mounts another \"connected component\" (i.e. container). When I try to test SampleComponent by

6条回答
  •  感情败类
    2020-12-24 06:51

    What I essentially did was bring in my redux store (and Provider) and wrapped it in a utility component as follows:

    export const CustomProvider = ({ children }) => {
      return (
        
          {children}
        
      );
    };
    

    then, I mount the SampleComponent and run tests against it:

    it('contains  Component', () => {
      const wrapper = mount(
        
          
        
      );
      expect(wrapper.find(ChildComponent)).to.have.length(1);
    });
    

提交回复
热议问题