Open telored opened 6 years ago
You may create a TestProvider which may render styles to include them into snapshot too.
@telored , I was able to resolve this. Here are the steps to fix this:
Follow the steps described in this article: https://medium.com/@m.izadmehr/react-starter-kit-testing-isomorphic-style-loader-with-jest-and-enzyme-fd361b0591f0
Basiclly, you'll need to create a mock folder inside of your tools directory, which will contain a withStyles.js . Next in your jest.config.js change your moduleNameMapper to:
moduleNameMapper: {
'\.(css|less|sass|scss)$': 'identity-obj-proxy',
'isomorphic-style-loader/lib/withStyles':
'
when i try to make snapshot testing of some component that uses withStyles i get the following error:
TypeError: Cannot read property 'apply' of undefined
my test file:
import React from 'react'; import renderer from 'react-test-renderer'; import Page from './Page';
describe('Pruebas ', () => {
it('Snapshot test', () => {
const tree = renderer.create(
,
);
expect(tree).toMatchSnapshot();
});
});