Enzyme expects an adapter to be configured

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

    Create a file named setupTests.js in the root of your project. jest will automatically look for this file before running any test suits. Add the following content to the file.

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

    Note: the filename should be exactly the same.no need to import this setupTests.js file into your test files.it will work automatically

提交回复
热议问题