I don't know why i get empty shallowWrapper object when i run snapshot test, i am using Jest and Enzyme:
What i get in App.test.js.snap file:
// Jest Snapshot v1, "goo.gl/fbAQLP"
exports[`renders App component 1`] = `ShallowWrapper {}`;
my package.json file:
{
"name": "test",
"version": "0.1.0",
"private": true,
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.30",
"@fortawesome/free-solid-svg-icons": "^5.14.0",
"@fortawesome/react-fontawesome": "^0.1.11",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"bootstrap": "^4.5.2",
"install": "^0.13.0",
"npm": "^6.14.8",
"react": "^16.13.1",
"react-bootstrap": "^1.3.0",
"react-dom": "^16.13.1",
"react-router-dom": "^5.2.0",
"react-scripts": "^4.0.0-next.98"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.4",
"jest": "^26.4.2"
}
}
App.test.js file
import { shallow } from 'enzyme';
import React from 'react';
import App from './App';
it('renders App component', () => {
expect(shallow(<App />)).toMatchSnapshot();
})
setupTests.js file:
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
configure({
adapter: new Adapter()
});
Why i get that empty shallowWrapper object, I suspected the version of jest after some search, but even downgrading didn't solve it.
I ran into similar problem and playing around with jest help me got through it. I suggest you can clear the jest cache and then update the snapshots using
jest --clearCache && jest -uand then run your test.Also for your snapshot, I'd recommend you to use
enzyme-to-jsonserialiser (https://www.npmjs.com/package/enzyme-to-json) and modify your test to: