From fde61b3f2224f48a071e6372b09eb2dec53c635b Mon Sep 17 00:00:00 2001 From: Tom Thumb Date: Sun, 22 Jan 2023 09:26:28 -0500 Subject: [PATCH] docs: update Snapshot section to provide details on how to use with concurrent test close #2729 --- docs/guide/features.md | 14 +++++++------- docs/guide/snapshot.md | 8 ++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/docs/guide/features.md b/docs/guide/features.md index 0e587193931a..c0b17333e88b 100644 --- a/docs/guide/features.md +++ b/docs/guide/features.md @@ -44,7 +44,7 @@ Learn more about [Test Filtering](./filtering.md). ## Running tests concurrently -Use `.concurrent` in consecutive tests to run them in parallel. +Use `.concurrent` in consecutive tests to run them in parallel. Also, be sure to use `expect` from the [Test Context](/guide/test-context.md) to ensure the right test is being detected. ```ts import { describe, it } from 'vitest' @@ -52,8 +52,8 @@ import { describe, it } from 'vitest' // The two tests marked with concurrent will be run in parallel describe('suite', () => { it('serial test', async () => { /* ... */ }) - it.concurrent('concurrent test 1', async () => { /* ... */ }) - it.concurrent('concurrent test 2', async () => { /* ... */ }) + it.concurrent('concurrent test 1', async ({ expect }) => { /* ... */ }) + it.concurrent('concurrent test 2', async ({ expect }) => { /* ... */ }) }) ``` @@ -64,13 +64,13 @@ import { describe, it } from 'vitest' // All tests within this suite will be run in parallel describe.concurrent('suite', () => { - it('concurrent test 1', async () => { /* ... */ }) - it('concurrent test 2', async () => { /* ... */ }) - it.concurrent('concurrent test 3', async () => { /* ... */ }) + it('concurrent test 1', async ({ expect }) => { /* ... */ }) + it('concurrent test 2', async ({ expect }) => { /* ... */ }) + it.concurrent('concurrent test 3', async ({ expect }) => { /* ... */ }) }) ``` -You can also use `.skip`, `.only`, and `.todo` with concurrent suites and tests. Read more in the [API Reference](../api/#concurrent). +You can also use `.skip`, `.only`, and `.todo` with concurrent suites and tests. Read more in the [API Reference](../api/#test-concurrent). ## Snapshot diff --git a/docs/guide/snapshot.md b/docs/guide/snapshot.md index 92ed25b1e085..2c54cf990aa0 100644 --- a/docs/guide/snapshot.md +++ b/docs/guide/snapshot.md @@ -33,6 +33,10 @@ exports['toUpperCase 1'] = '"FOOBAR"' The snapshot artifact should be committed alongside code changes, and reviewed as part of your code review process. On subsequent test runs, Vitest will compare the rendered output with the previous snapshot. If they match, the test will pass. If they don't match, either the test runner found a bug in your code that should be fixed, or the implementation has changed and the snapshot needs to be updated. +::: warning +When using Snapshots with async concurrent tests, you need to use `expect` from the [Test Context](/guide/test-context.md) to ensure the right test is being detected. +::: + ## Inline Snapshots Similarly, you can use the [`toMatchInlineSnapshot()`](/api/#tomatchinlinesnapshot) to store the snapshot inline within the test file. @@ -59,6 +63,10 @@ it('toUpperCase', () => { This allows you to see the expected output directly without jumping across different files. +::: warning +When using Snapshots with async concurrent tests, you need to use `expect` from the [Test Context](/guide/test-context.md) to ensure the right test is being detected. +::: + ## Updating Snapshots When the received value doesn't match the snapshot, the test fails and shows you the difference between them. When the snapshot change is expected, you may want to update the snapshot from the current state.