docs: clarify expect docs (#7853)

This commit is contained in:
Vladimir 2025-04-18 09:14:38 +02:00 committed by GitHub
parent d97f6d4807
commit ed9ee9d4ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,7 +6,19 @@ The following types are used in the type signatures below
type Awaitable<T> = T | PromiseLike<T>
```
`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 {
<T>(actual: T, message?: string): Assertion<T>
extend: (expects: MatchersObject) => void
anything: () => any
any: (constructor: unknown) => any
getState: () => MatcherState
setState: (state: Partial<MatcherState>) => 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.