You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/ExpectAPI.md
+30Lines changed: 30 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -156,6 +156,36 @@ This will print something like this:
156
156
157
157
When an assertion fails, the error message should give as much signal as necessary to the user so they can resolve their issue quickly. You should craft a precise failure message to make sure users of your custom assertions have a good developer experience.
158
158
159
+
#### Custom snapshot matchers
160
+
161
+
To use snapshot testing inside of your custom matcher you can import `jest-snapshot` and use it from within your matcher.
162
+
163
+
Here's a simple snapshot matcher that trims a string to store for a given length, `.toMatchTrimmedSnapshot(length)`:
expect('extra long string oh my gerd').toMatchTrimmedSnapshot(10);
180
+
});
181
+
182
+
/*
183
+
Stored snapshot will look like:
184
+
185
+
exports[`stores only 10 characters: toMatchTrimmedSnapshot 1`] = `"extra long"`;
186
+
*/
187
+
```
188
+
159
189
### `expect.anything()`
160
190
161
191
`expect.anything()` matches anything but `null` or `undefined`. You can use it inside `toEqual` or `toBeCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a non-null argument:
0 commit comments