[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

docs: document the assertion function limitation in in-source testing (#10527)

authored by

koutaro-masaki and committed by
GitHub
(Jun 7, 2026, 10:53 AM +0200) 4c84cbcf bdd98543

+32
+28
docs/api/assert.md
··· 2 2 3 3 Vitest reexports the `assert` method from [`chai`](https://www.chaijs.com/api/assert/) for verifying invariants. 4 4 5 + ::: warning In-Source Testing {#in-source-testing} 6 + When using [assertion functions](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions) such as `assert` from `import.meta.vitest` in [in-source tests](/guide/in-source), TypeScript reports error `TS2775` because they must be called via an explicitly annotated name. Annotate the variable with `Chai.Assert` or call it directly: 7 + 8 + ::: code-group 9 + ```ts [Annotated variable] 10 + if (import.meta.vitest) { 11 + const { test, assert } = import.meta.vitest // [!code --] 12 + const { test } = import.meta.vitest // [!code ++] 13 + const assert: Chai.Assert = import.meta.vitest.assert // [!code ++] 14 + 15 + test('assert', () => { 16 + assert('foo' !== 'bar', 'foo should not be equal to bar') 17 + }) 18 + } 19 + ``` 20 + ```ts [Direct call] 21 + if (import.meta.vitest) { 22 + const { test, assert } = import.meta.vitest // [!code --] 23 + const { test } = import.meta.vitest // [!code ++] 24 + 25 + test('assert', () => { 26 + assert('foo' !== 'bar', 'foo should not be equal to bar') // [!code --] 27 + import.meta.vitest!.assert('foo' !== 'bar', 'foo should not be equal to bar') // [!code ++] 28 + }) 29 + } 30 + ``` 31 + ::: 32 + 5 33 ## assert 6 34 7 35 - **Type:** `(expression: any, message?: string) => asserts expression`
+4
docs/guide/in-source.md
··· 152 152 153 153 Reference to [`examples/in-source-test`](https://github.com/vitest-dev/vitest/tree/main/examples/in-source-test) for the full example. 154 154 155 + ::: warning 156 + There is a limitation when using [assertion functions](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions) such as `assert` in in-source tests. See [`assert`](/api/assert#in-source-testing) for details and workarounds. 157 + ::: 158 + 155 159 ## Notes 156 160 157 161 This feature could be useful for: