-
Notifications
You must be signed in to change notification settings - Fork 64
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
Strange snapshot output with High Order Components #42
Comments
Hi! Yeah |
I'll mark this as invalid for now because the output looks like what's expected to me, feel free to comment if you need help. |
Not to be a pest, but I happen to side with @james-s-turner on this issue --- to my mind, the value of snapshots is that they are like freebie pinning tests, allowing you to refactor code in confidence that you haven't broken expected outputs (i.e. HTML). But if the serializer output includes internal details like Component names and prop values, it's no longer useful for refactoring, since those things are exactly what you'd be changing. I also take your point that the Any chance you'd be willing to reconsider this issue? |
Hi @esimons, My goal is to give output that looks like what you get using the Enzyme For example I have components like that: function SubComponent(props) {
return <span>The value is {props.value}</span>;
}
function MyComponent(props) {
return <SubComponent value={props.value}/>;
} If I want to unit test <SubComponent value={1}/> than this: <span>The value is 1</span> The reason is that I don't want Let's say that I have 100 snapshots for I can hardly see a use case where you would like to do that, and if you do, the You can also do something like that: expect(wrapper.find('SubComponent').mount()).toMatchSnapshot(); which will show what |
Hey @adriantoine thanks for responding so quickly! You make a great point, and I think you're right that in most cases we should be treating these snapshots as unit tests, rather than large-scoped tests of multiple components. In that sense My issue was that I was trying to use I can dig that we're not able to mess with the Enzyme wrappers here, though. I think I'll just have to change up my approach a bit. Thanks again, much appreciated! |
I agree with @esimons and @james-s-turner. If a function produces the same output the test should pass regardless of implementation details. When you change a sub-component, the parent component's unit tests should fail because it's now doing something different. |
I'm trying to snapshot a routed redux app, my test code is as follows:
I'm using chai-jest-snapshot to do the snapshotting. The output I see in the snapshot file looks like this:
Snapshot testing fails because some key values differ on each test execution.
However when I use react-test-renderer the snapshot output is just HTML and the snapshot comparisons work fine:
The code I ran to produce this is:
So the only difference appears to be calling the
enzymeToJson()
method rather than using the react-test-renderer equivalent.Any help gratefully received.
The text was updated successfully, but these errors were encountered: