From ed9ee9d4bae9f3511655cc6fa6f6daa15d68119f Mon Sep 17 00:00:00 2001 From: Vladimir Date: Fri, 18 Apr 2025 09:14:38 +0200 Subject: [PATCH] docs: clarify `expect` docs (#7853) --- docs/api/expect.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/api/expect.md b/docs/api/expect.md index 7ed0de0a6..57af519d8 100644 --- a/docs/api/expect.md +++ b/docs/api/expect.md @@ -6,7 +6,19 @@ The following types are used in the type signatures below type Awaitable = T | PromiseLike ``` -`expect` is used to create assertions. In this context `assertions` are functions that can be called to assert a statement. Vitest provides `chai` assertions by default and also `Jest` compatible assertions built on top of `chai`. +`expect` is used to create assertions. In this context `assertions` are functions that can be called to assert a statement. Vitest provides `chai` assertions by default and also `Jest` compatible assertions built on top of `chai`. Unlike `Jest`, Vitest supports a message as the second argument - if the assertion fails, the error message will be equal to it. + +```ts +export interface ExpectStatic extends Chai.ExpectStatic, AsymmetricMatchersContaining { + (actual: T, message?: string): Assertion + extend: (expects: MatchersObject) => void + anything: () => any + any: (constructor: unknown) => any + getState: () => MatcherState + setState: (state: Partial) => void + not: AsymmetricMatchersContaining +} +``` For example, this code asserts that an `input` value is equal to `2`. If it's not, the assertion will throw an error, and the test will fail. -- 2.51.2