Skip to content

Commit

Permalink
[Docs] Clarified the use of literal values as property matchers in to…
Browse files Browse the repository at this point in the history
…MatchSnapshot() (#6807)

* docs: Clarified the use of literal values as property matchers

* Fixed typo: snaptshot -> snapshot
  • Loading branch information
InExtremaRes authored and SimenB committed Aug 6, 2018
1 parent 32e2649 commit 277c547
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/ExpectAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
24 changes: 24 additions & 0 deletions docs/SnapshotTesting.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Date>,
"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.
Expand Down

0 comments on commit 277c547

Please sign in to comment.