Skip to content

Commit

Permalink
docs: update expect.soft related documentation (#3535)
Browse files Browse the repository at this point in the history
Co-authored-by: Anjorin Damilare <damilareanjorin1@gmail.com>
Co-authored-by: Vladimir <sleuths.slews0s@icloud.com>
  • Loading branch information
3 people committed Jun 15, 2023
1 parent 0cbb07b commit dff19bc
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions docs/api/expect.md
Expand Up @@ -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.
Expand Down

0 comments on commit dff19bc

Please sign in to comment.