-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Expose toMatchSnapshot
in custom matchers
#6144
Comments
The same outcome could currently be achieved using the following // jest-setup.js
const snapshot = require('jest-snapshot');
function toMatchSnapshotTrimmed(received, customName){
return snapshot.toMatchSnapshot.call(this, received.trim(), customName);
}
expect.extend({
toMatchSnapshotTrimmed
}) By the way, you can't use arrow function for custom matcher, |
The idea to easily extend snapshot matchers is pretty neat. But, to do it this way, we would need to couple Since we can achieve the same pretty easily in user space, I think we're good leaving the scope of the I'd be really happy to merge a PR explaining how to create a custom snapshot matcher in our Expect docs 🙂 |
## Summary Add docs for how to write custom matchers that use snapshot testing, following up from this: #6144 (comment)
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
🚀 Feature Proposal
Expose
toMatchSnapshot
in custom matchersMotivation
Snapshots can seem to vary in outcome across operating systems (see #6102 and #6113). To help prevent this we could normalise the differences in the snapshot.
Currently to normalise a snapshot you would have to do it in the data being snapshotted. By exposing
toMatchSnapshot
in custom matchers we can create reusable assertions .This issue is related to #6115 and @rickhanlonii's comment on how to normalise whitespace in snapshots from within a custom matcher.
Example
The text was updated successfully, but these errors were encountered: