Answer the question
In order to leave comments, you need to log in
How to test components wrapped with withStyles material-ui?
I am developing an application with the material-ui framework. Started writing tests and ran into a problem when writing tests for a component wrapped in the withStyles HOC.
This error pops up:
TypeError: Cannot read property 'main' of undefined
label: {
fontSize: 12,
color: palette.gray.main
}
Answer the question
In order to leave comments, you need to log in
I found such a solution, which of the experts, correct if something is wrong and then how to do it more correctly:
I import from the 'react-test-renderer' package:
From a component, I import a component that is not wrapped in HOC with a regular export.
And now there is no deep rendering for the snapshot:
it('Profile renders snapshot', () => {
const renderer = new ShallowRenderer();
const result = renderer.render(<Profile />);
expect(result).toMatchSnapshot();
});
it('ProfileMainInfo renders snapshot', () => {
const renderer = new ShallowRenderer();
const result = renderer.render(<ProfileMainInfo.wrappedComponent {...props} />);
expect(result).toMatchSnapshot();
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question