Skip to content

Commit 277c547

Browse files
InExtremaResSimenB
authored andcommitted
[Docs] Clarified the use of literal values as property matchers in toMatchSnapshot() (#6807)
* docs: Clarified the use of literal values as property matchers * Fixed typo: snaptshot -> snapshot
1 parent 32e2649 commit 277c547

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

docs/ExpectAPI.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ test('this house has my desired features', () => {
10251025

10261026
This ensures that a value matches the most recent snapshot. Check out [the Snapshot Testing guide](SnapshotTesting.md) for more information.
10271027

1028-
The optional `propertyMatchers` argument allows you to specify asymmetric matchers which are verified instead of the exact values.
1028+
The optional `propertyMatchers` argument allows you to specify asymmetric matchers which are verified instead of the exact values. Any value will be matched exactly if not provided as a matcher.
10291029

10301030
The last argument allows you option to specify a snapshot name. Otherwise, the name is inferred from the test.
10311031

docs/SnapshotTesting.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,30 @@ Object {
187187
`;
188188
```
189189

190+
Any given value that is not a matcher will be checked exactly and saved to the snapshot:
191+
192+
```javascript
193+
it('will check the values and pass', () => {
194+
const user = {
195+
createdAt: new Date(),
196+
name: 'Bond... James Bond',
197+
};
198+
199+
expect(user).toMatchSnapshot({
200+
createdAt: expect.any(Date),
201+
name: 'Bond... James Bond',
202+
});
203+
});
204+
205+
// Snapshot
206+
exports[`will check the values and pass 1`] = `
207+
Object {
208+
"createdAt": Any<Date>,
209+
"name": 'Bond... James Bond',
210+
}
211+
`;
212+
```
213+
190214
## Best Practices
191215

192216
Snapshots are a fantastic tool for identifying unexpected interface changes within your application – whether that interface is an API response, UI, logs, or error messages. As with any testing strategy, there are some best-practices you should be aware of, and guidelines you should follow, in order to use them effectively.

0 commit comments

Comments
 (0)