diff --git a/docs/ExpectAPI.md b/docs/ExpectAPI.md index 075ee7d2c8e8..d3da403f2930 100644 --- a/docs/ExpectAPI.md +++ b/docs/ExpectAPI.md @@ -1025,7 +1025,7 @@ test('this house has my desired features', () => { This ensures that a value matches the most recent snapshot. Check out [the Snapshot Testing guide](SnapshotTesting.md) for more information. -The optional `propertyMatchers` argument allows you to specify asymmetric matchers which are verified instead of the exact values. +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. The last argument allows you option to specify a snapshot name. Otherwise, the name is inferred from the test. diff --git a/docs/SnapshotTesting.md b/docs/SnapshotTesting.md index 9b79f7035548..8123b6e69ba8 100644 --- a/docs/SnapshotTesting.md +++ b/docs/SnapshotTesting.md @@ -187,6 +187,30 @@ Object { `; ``` +Any given value that is not a matcher will be checked exactly and saved to the snapshot: + +```javascript +it('will check the values and pass', () => { + const user = { + createdAt: new Date(), + name: 'Bond... James Bond', + }; + + expect(user).toMatchSnapshot({ + createdAt: expect.any(Date), + name: 'Bond... James Bond', + }); +}); + +// Snapshot +exports[`will check the values and pass 1`] = ` +Object { + "createdAt": Any, + "name": 'Bond... James Bond', +} +`; +``` + ## Best Practices 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.