-
-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tests pass when styles change on a nested component using enzyme shallow. #12
Comments
Hello Tyler, thanks for opening the issue. I don't believe this is an issue or something to solve, but I'll be happy to discuss further in case you do. I'm going to close this but anyone should feel free to reopen it in case we want to address the problem. |
That does make sense. I think it was a mistake in how I was viewing the In that case, when it comes to testing examples like this (where we have two components that we would like to test, but we don't want to do a deep render because the contents have a lot of stuff in the tree that we are testing elsewhere), is there a decent way of snapshotting the styles? The options I can think of are:
Thanks for your help on this! |
This is definitely the way to go! You could also just partially export it if you don't want to add another file: export const Title = // ...
export default class FullComponent extends React.Component { /* ... */ } Then you can import both in your tests and test the separately: import FullComponent, { Title } from '../FullComponent';
describe('<FullComponent />', () => { /* ...shallow render <FullComponent />... */ })
describe('<Title />', () => { /* ...shallow render <Titlte /> ... */ }) |
Perfect. Thanks for the advice @mxstbr. I'll get to it! |
I fell into the same issue and finally I realized to use your second option of deep rendering with mocking (ignoring) the nested components defining empty functions. jest.mock('../Inner', () => 'inner')
const snapshot = mount(<Wrapper />) I documented it here, so I hope it will be helpful for some others... https://medium.com/@melounek/jest-snapshots-with-nested-components-c08ceef34108 |
Thank you very much, @melounek. |
Hi @MicheleBertoli . First off, thanks for making this package - it looks like it could be super useful!
I'm really keen to get using
jest-styled-components
but have run into this issue. To reproduce:test/index.spec.js
to remove thereact-test-renderer
test so that we don't get confused by test output.Title
component.If we inspect the snapshot the nested
Title
component is serialised as astyled.h1
and there is no information about the styles that have been applied. I'd like to try help with this if I get a chance.Thanks,
Tyler
The text was updated successfully, but these errors were encountered: