This is my __tests__/App.js
file:
import React from \'react\';
import ReactDOM from \'react-dom\';
import App from \'../src/containers/App\';
it(\'
In the package.json if using jest
"scripts":{
"test": "jest --env=jsdom"
}
Placing the comment at the top of your unit-test source
/**
* @jest-environment jsdom
*/
signals jest to mock document and window.
If you are using create-react-app
, make sure to run yarn test
instead of yarn jest
or something else.
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(<App />);
});