You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api/expect.md
+32Lines changed: 32 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,38 @@ type Awaitable<T> = T | PromiseLike<T>
27
27
`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).
`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
+
30
62
## not
31
63
32
64
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