Skip to content

Commit 6327019

Browse files
Apply suggestions from code review
Co-authored-by: Tom Mrazauskas <[email protected]>
1 parent b7b81a1 commit 6327019

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

docs/ExpectAPI.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -744,13 +744,13 @@ You can provide an optional `propertyMatchers` object argument, which has asymme
744744

745745
You can provide an optional `hint` string argument that is appended to the test name. Although Jest always appends a number at the end of a snapshot name, short descriptive hints might be more useful than numbers to differentiate **multiple** snapshots in a **single** `it` or `test` block. Jest sorts snapshots by name in the corresponding `.snap` file.
746746

747-
### `.toMatchNamedSnapshot(propertyMatchers?, snapshotName?)`
747+
### `.toMatchNamedSnapshot(snapshotName, propertyMatchers?)`
748748

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

751751
You can provide an optional `propertyMatchers` object argument, which has asymmetric matchers as values of a subset of expected properties, **if** the received value will be an **object** instance. It is like `toMatchObject` with flexible criteria for a subset of properties, followed by a snapshot test as exact criteria for the rest of the properties.
752752

753-
You can provide an optional `snapshotName` string argument that functions as the test name. By providing a snapshot name (as opposed to letting Jest infer the name from context) snapshot names can be guaranteed to be consistent across test runs, whatever the context at the time of evaluation. Jest always appends a number at the end of a snapshot name.
753+
By setting the `snapshotName` explicitly (as opposed to letting Jest infer the name from context) it can be guaranteed to be consistent across test runs, whatever the context at the time of evaluation. Jest always appends a number at the end of a snapshot name.
754754

755755
Jest sorts snapshots by name in the corresponding `.snap` file.
756756

@@ -886,11 +886,11 @@ exports[`drinking flavors throws on octopus 1`] = `"yuck, octopus flavor"`;
886886

887887
Check out [React Tree Snapshot Testing](/blog/2016/07/27/jest-14) for more information on snapshot testing.
888888

889-
### `.toThrowErrorMatchingNamedSnapshot(snapshotName?)`
889+
### `.toThrowErrorMatchingNamedSnapshot(snapshotName)`
890890

891-
Use `.toThrowErrorMatchingNamedSnapshot` to test that a functino throws an error matching the most recent snapshot when it is called.
891+
Use `.toThrowErrorMatchingNamedSnapshot` to test that a function throws an error matching the most recent snapshot when it is called.
892892

893-
You can provide an optional `snapshotName` string argument that functions as the test name. By providing a snapshot name (as opposed to letting Jest infer the name from context) snapshot names can be guaranteed to be consistent across test runs, whatever the context at the time of evaluation. Jest always appends a number at the end of a snapshot name.
893+
By setting the `snapshotName` explicitly (as opposed to letting Jest infer the name from context) it can be guaranteed to be consistent across test runs, whatever the context at the time of evaluation. Jest always appends a number at the end of a snapshot name.
894894

895895
### `.toThrowErrorMatchingInlineSnapshot(inlineSnapshot)`
896896

docs/SnapshotTesting.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,11 @@ Now, every time the snapshot test case runs, `Date.now()` will return `148236336
264264

265265
Always strive to use descriptive test and/or snapshot names for snapshots. The best names describe the expected snapshot content. This makes it easier for reviewers to verify the snapshots during review, and for anyone to know whether or not an outdated snapshot is the correct behavior before updating.
266266

267-
The default matcher, `toMatchSnapshot`, infers the name based on the test function context when the snapshot is evaluated. This can cause snapshots in tests that are run concurrently to have different names on each test run. If you want to guarantee consistent names, you can use `toMatchNamedSnapshot` as an alternative matcher.
267+
:::tip
268+
269+
The `toMatchSnapshot` matcher infers the name based on the test function context when the snapshot is evaluated. This can cause snapshots in tests that are run concurrently to have different names on each test run. If you want to guarantee consistent names, you can use the `toMatchNamedSnapshot` matcher.
270+
271+
:::
268272

269273
For example, compare:
270274

0 commit comments

Comments
 (0)