diff --git a/docs/api/expect.md b/docs/api/expect.md index efab86e8b9a7..d2a83597a459 100644 --- a/docs/api/expect.md +++ b/docs/api/expect.md @@ -27,6 +27,38 @@ type Awaitable = T | PromiseLike `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.