Skip to content

Commit

Permalink
docs: update Snapshot section to provide details on how to use with c…
Browse files Browse the repository at this point in the history
…oncurrent test

close vitest-dev#2729
  • Loading branch information
Tom Thumb authored and asdfjkalsdfla committed Feb 12, 2023
1 parent 4ea1f1d commit 539f55e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 6 additions & 6 deletions docs/guide/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ 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'

// 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 }) => { /* ... */ })
})
```

Expand All @@ -64,9 +64,9 @@ 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 }) => { /* ... */ })
})
```

Expand Down
8 changes: 8 additions & 0 deletions docs/guide/snapshot.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/expect#tomatchinlinesnapshot) to store the snapshot inline within the test file.
Expand All @@ -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.
Expand Down

0 comments on commit 539f55e

Please sign in to comment.