“ReferenceError: document is not defined” when trying to test a create-react-app project

前端 未结 4 2294
醉话见心
醉话见心 2021-02-18 13:42

This is my __tests__/App.js file:

import React from \'react\';
import ReactDOM from \'react-dom\';
import App from \'../src/containers/App\';

it(\'         


        
4条回答
  •  情深已故
    2021-02-18 14:35

    For me either of these worked

    In package.json file adding test script env flag

    "scripts": {
       "test": "react-scripts test --env=jsdom"
    }
    

    Using enzyme

     import { shallow } from 'enzyme';
    
     it('renders without crashing', () => {
      shallow();
     });
    

提交回复
热议问题