Skip to content

Commit fee7d8b

Browse files
authored
docs: fix reference to onTestFailed on the context (vitest-dev#5394)
1 parent ab25a52 commit fee7d8b

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Diff for: docs/api/index.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ These hooks will throw an error if they are called outside of the test body.
940940

941941
This hook is always called after the test has finished running. It is called after `afterEach` hooks since they can influence the test result. It receives a `TaskResult` object with the current test result.
942942

943-
```ts
943+
```ts {1,5}
944944
import { onTestFinished, test } from 'vitest'
945945

946946
test('performs a query', () => {
@@ -953,12 +953,12 @@ test('performs a query', () => {
953953
::: warning
954954
If you are running tests concurrently, you should always use `onTestFinished` hook from the test context since Vitest doesn't track concurrent tests in global hooks:
955955

956-
```ts
956+
```ts {3,5}
957957
import { test } from 'vitest'
958958

959-
test.concurrent('performs a query', (t) => {
959+
test.concurrent('performs a query', ({ onTestFinished }) => {
960960
const db = connectDb()
961-
t.onTestFinished(() => db.close())
961+
onTestFinished(() => db.close())
962962
db.query('SELECT * FROM users')
963963
})
964964
```
@@ -993,7 +993,7 @@ test('performs an organization query', async () => {
993993

994994
This hook is called only after the test has failed. It is called after `afterEach` hooks since they can influence the test result. It receives a `TaskResult` object with the current test result. This hook is useful for debugging.
995995

996-
```ts
996+
```ts {1,5-7}
997997
import { onTestFailed, test } from 'vitest'
998998

999999
test('performs a query', () => {
@@ -1008,10 +1008,10 @@ test('performs a query', () => {
10081008
::: warning
10091009
If you are running tests concurrently, you should always use `onTestFailed` hook from the test context since Vitest doesn't track concurrent tests in global hooks:
10101010

1011-
```ts
1011+
```ts {3,5-7}
10121012
import { test } from 'vitest'
10131013

1014-
test.concurrent('performs a query', (t) => {
1014+
test.concurrent('performs a query', ({ onTestFailed }) => {
10151015
const db = connectDb()
10161016
onTestFailed((result) => {
10171017
console.log(result.errors)

0 commit comments

Comments
 (0)