Thanks for reporting an issue to us! We're glad you are using and invested in Enzyme.
Before submitting, please read over our commonly reported issues to prevent duplicates!
If you haven't found any duplicated issues, please report it with your environment!
npm run test is updating the snapshot without update flag.
div className={classNames(styles.hello, 'x y')} changed it to following
div className={classNames(styles.hello, 'x')}
and then I ran npm run test (which is not using update flag) but it updated the snapshot and hence build gets passed.
1) first of all it should not update the snapshot if we do not pass the update flag
enzyme: 3.2.0
karma: 1.7.1
| library | version
| ------------------- | -------
| enzyme | 3.2.0
| react | 16.4.1
| react-dom | 16.4.1
| react-test-renderer |
| adapter (below) |
enzyme does not support or encourage snapshot testing; the closest we offer is .debug().
I'll close this, but am happy to reopen if you're seeing an issue there.
enzyme does not support or encourage snapshot testing
@ljharb Could you elaborate a bit on this? The word 'snapshot' is missing from the official documentation, which I interpret as more agnostic than specifically not encouraging/supporting the testing methodology. Is the thought here that a well-designed React application shouldn't _need_ snapshot testing, as explicit assertions should be simple enough with the combination of a well-componentized application and enzyme tooling?
@c3chong the lack of a mention is a discouragement :-)
Snapshot testing is inherently brittle. What happens in practice is that developers rubber-stamp snapshot diffs without fully understanding why they've changed, and the false sense of confidence given causes developers to not thoroughly review the code. The only time snapshots are valuable is when you're doing a "no observable changes" refactor, which is rare, and in most cases, you don't actually care about the rendering hierarchy - you care about specific components being rendered, specific content being rendered, etc - which is what explicit tests address.
In addition, a snapshot contains so much noise that there's no way to know what pieces are important, and which can be ignored, and it's not practical to review every snapshot change and assume they're all important.
@ljharb thank you! All that being said, should I expect inconsistent, incorrect, or untested behaviour when using snapshots with enzyme? I'm trying to discern whether, given the right use case, if it's safe to rely on snapshot tests when using the enzyme wrapper?
@c3chong you should expect all snapshot behavior to come from whatever non-enzyme tool you're using to work with them - jest, enzyme-to-json, etc. The closest thing enzyme provides and supports is .debug(). So how "safe" it is depends on how reliable those projects are - in my experience, snapshots aren't safe.