Skip to content

Commit

Permalink
Add ref to expect.assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
asdfjkalsdfla committed Feb 4, 2023
1 parent d0983a7 commit fa41cd4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion docs/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,15 @@ You cannot use this syntax, when using Vitest as [type checker](/guide/testing-t
test.todo.concurrent(/* ... */) // or test.concurrent.todo(/* ... */)
```

When using Snapshots with async concurrent tests, due to the limitation of JavaScript, you need to use the `expect` from the [Test Context](/guide/test-context.md) to ensure the right test is being detected.
When using Snapshots with async concurrent tests, you need to use `expect` from the [Test Context](/guide/test-context.md) and call `expect.assertions` to ensure the test will detect any failures.

```ts
test.concurrent('test 1', async ({ expect }) => {
expert.assertions(1)
expect(foo).toMatchSnapshot()
})
test.concurrent('test 2', async ({ expect }) => {
expert.assertions(1)
expect(foo).toMatchSnapshot()
})
```
Expand Down
6 changes: 5 additions & 1 deletion docs/guide/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Learn more about [Test Filtering](./filtering.md).

## Running tests concurrently

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.
Use `.concurrent` in consecutive tests to run them in parallel.

```ts
import { describe, it } from 'vitest'
Expand Down Expand Up @@ -72,6 +72,10 @@ describe.concurrent('suite', () => {

You can also use `.skip`, `.only`, and `.todo` with concurrent suites and tests. Read more in the [API Reference](../api/#test-concurrent).

::: warning
When using Snapshots with async concurrent tests, you need to use `expect` from the [Test Context](/guide/test-context.md) and call `expect.assertions` to ensure the test will detect any failures.
:::

## Snapshot

[Jest-compatible](https://jestjs.io/docs/snapshot-testing) snapshot support.
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/snapshot.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ 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.
When using Snapshots with async concurrent tests, you need to use `expect` from the [Test Context](/guide/test-context.md) and call `expect.assertions` to ensure the test will detect any failures.
:::

## Inline Snapshots
Expand Down Expand Up @@ -64,7 +64,7 @@ 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.
When using Snapshots with async concurrent tests, you need to use `expect` from the [Test Context](/guide/test-context.md) and call `expect.assertions` to ensure the test will detect any failures.
:::

## Updating Snapshots
Expand Down

0 comments on commit fa41cd4

Please sign in to comment.