Enzyme expects an adapter to be configured

前端 未结 15 1554
太阳男子
太阳男子 2020-12-24 04:53

I created a new React application by create-react-app and I wanted to write a unit test to a component named \"MessageBox\" that I created in the application. This is the un

15条回答
  •  离开以前
    2020-12-24 05:30

    Try sth like this;

    import React from 'react';
    import App from './containers/App';
    import enzyme from 'enzyme';
    import Adapter from 'enzyme-adapter-react-16';
    enzyme.configure({ adapter: new Adapter() });
    
    describe('App Screen', () => {
      let mountedAppScreen;
      let props;
    
      const appScreen = () => {
        if (!mountedAppScreen) {
          mountedAppScreen = enzyme.mount(
            
          );
        }
        return mountedAppScreen;
      }
      it("it always renders div", () => {
        const divs = appScreen().find("div");
        expect(divs.length).toBeGreaterThanOrEqual(1);
      });
    });
    

提交回复
热议问题