Enzyme expects an adapter to be configured

前端 未结 15 1617
太阳男子
太阳男子 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:09

    For me when using React with create-react-app I had to make sure the file name was correct. The file has to be src/setupTests.js with an s at the end of Tests.

    Inside setupTests.js is the following:

    import { configure } from "enzyme";
    import Adapter from "enzyme-adapter-react-16";
    
    configure({ adapter: new Adapter() });
    
    

    When running npm run test it auto finds the setupTests.js file. There is no need to import it into each test file.

提交回复
热议问题