npm i -D enzyme jest-cli enzyme-adapter-react-16
npm i -D redux-mock-store fetch-mock
npm i -S redux react-redux redux-thunk
import React from 'react';
import { render } from 'react-dom';
import App from './components/App';
render(<App />, document.getElementById('root'));
import React from 'react';
import { shallow } from 'enzyme';
import App from './App';
const app = shallow(<App />);
it('renders correctly', () => {
expect(app).toMatchSnapshot();
});
setupTests.js
in src
folder.
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
configure({ adapter: new Adapter() });
npm run test -- --coverage
In package.json
"jest": {
"collectCoverageFrom": [
"src/**/*.js",
"!src/index.js"
]
}
console.log(app.debug());