Skip to content

Commit dff19bc

Browse files
Dunqingdammy001sheremet-va
authored
docs: update expect.soft related documentation (#3535)
Co-authored-by: Anjorin Damilare <[email protected]> Co-authored-by: Vladimir <[email protected]>
1 parent 0cbb07b commit dff19bc

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

docs/api/expect.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,38 @@ type Awaitable<T> = T | PromiseLike<T>
2727
`expect` has no effect on testing types, if the expression doesn't have a type error. If you want to use Vitest as [type checker](/guide/testing-types), use [`expectTypeOf`](/api/expect-typeof) or [`assertType`](/api/assert-type).
2828
:::
2929

30+
## soft
31+
32+
- **Type:** `ExpectStatic & (actual: any) => Assertions`
33+
34+
`expect.soft` functions similarly to `expect`, but instead of terminating the test execution upon a failed assertion, it continues running and marks the failure as a test failure. All errors encountered during the test will be displayed until the test is completed.
35+
36+
```ts
37+
import { expect, test } from 'vitest'
38+
39+
test('expect.soft test', () => {
40+
expect.soft(1 + 1).toBe(3) // mark the test as fail and continue
41+
expect.soft(1 + 2).toBe(4) // mark the test as fail and continue
42+
})
43+
// At the end of the test, the above errors will be output.
44+
```
45+
46+
It can also be used with `expect`. if `expect` assertion fails, the test will be terminated and all errors will be displayed.
47+
48+
```ts
49+
import { expect, test } from 'vitest'
50+
51+
test('expect.soft test', () => {
52+
expect.soft(1 + 1).toBe(3) // mark the test as fail and continue
53+
expect(1 + 2).toBe(3) // failed and terminate the test, all previous errors will be output
54+
expect.soft(1 + 2).toBe(4) // do not run
55+
})
56+
```
57+
58+
::: warning
59+
`expect.soft` can only be used inside the [`test`](/api/#test) function.
60+
:::
61+
3062
## not
3163

3264
Using `not` will negate the assertion. For example, this code asserts that an `input` value is not equal to `2`. If it's equal, the assertion will throw an error, and the test will fail.

0 commit comments

Comments
 (0)