Skip to content

Commit

Permalink
update tip on snapshot testing document
Browse files Browse the repository at this point in the history
  • Loading branch information
bakamitai456 committed Jun 15, 2023
1 parent 58acde3 commit 23d8053
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions docs/SnapshotTesting.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ More information on how snapshot testing works and why we built it can be found

:::

:::tip

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.

:::

### Updating Snapshots

It's straightforward to spot when a snapshot test fails after a bug has been introduced. When that happens, go ahead and fix the issue and make sure your snapshot tests are passing again. Now, let's talk about the case when a snapshot test is failing due to an intentional implementation change.
Expand Down Expand Up @@ -264,10 +270,6 @@ Now, every time the snapshot test case runs, `Date.now()` will return `148236336

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.

:::tip

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.

:::

For example, compare:
Expand Down

0 comments on commit 23d8053

Please sign in to comment.