mirror of
https://github.com/vitest-dev/vitest.git
synced 2026-02-01 17:36:51 +00:00
docs: update expect.soft related documentation (#3535)
Co-authored-by: Anjorin Damilare <damilareanjorin1@gmail.com> Co-authored-by: Vladimir <sleuths.slews0s@icloud.com>
This commit is contained in:
parent
0cbb07b404
commit
dff19bc268
@ -27,6 +27,38 @@ type Awaitable<T> = T | PromiseLike<T>
|
||||
`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).
|
||||
:::
|
||||
|
||||
## soft
|
||||
|
||||
- **Type:** `ExpectStatic & (actual: any) => Assertions`
|
||||
|
||||
`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.
|
||||
|
||||
```ts
|
||||
import { expect, test } from 'vitest'
|
||||
|
||||
test('expect.soft test', () => {
|
||||
expect.soft(1 + 1).toBe(3) // mark the test as fail and continue
|
||||
expect.soft(1 + 2).toBe(4) // mark the test as fail and continue
|
||||
})
|
||||
// At the end of the test, the above errors will be output.
|
||||
```
|
||||
|
||||
It can also be used with `expect`. if `expect` assertion fails, the test will be terminated and all errors will be displayed.
|
||||
|
||||
```ts
|
||||
import { expect, test } from 'vitest'
|
||||
|
||||
test('expect.soft test', () => {
|
||||
expect.soft(1 + 1).toBe(3) // mark the test as fail and continue
|
||||
expect(1 + 2).toBe(3) // failed and terminate the test, all previous errors will be output
|
||||
expect.soft(1 + 2).toBe(4) // do not run
|
||||
})
|
||||
```
|
||||
|
||||
::: warning
|
||||
`expect.soft` can only be used inside the [`test`](/api/#test) function.
|
||||
:::
|
||||
|
||||
## not
|
||||
|
||||
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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user