···2233Vitest reexports the `assert` method from [`chai`](https://www.chaijs.com/api/assert/) for verifying invariants.
4455+::: warning In-Source Testing {#in-source-testing}
66+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:
77+88+::: code-group
99+```ts [Annotated variable]
1010+if (import.meta.vitest) {
1111+ const { test, assert } = import.meta.vitest // [!code --]
1212+ const { test } = import.meta.vitest // [!code ++]
1313+ const assert: Chai.Assert = import.meta.vitest.assert // [!code ++]
1414+1515+ test('assert', () => {
1616+ assert('foo' !== 'bar', 'foo should not be equal to bar')
1717+ })
1818+}
1919+```
2020+```ts [Direct call]
2121+if (import.meta.vitest) {
2222+ const { test, assert } = import.meta.vitest // [!code --]
2323+ const { test } = import.meta.vitest // [!code ++]
2424+2525+ test('assert', () => {
2626+ assert('foo' !== 'bar', 'foo should not be equal to bar') // [!code --]
2727+ import.meta.vitest!.assert('foo' !== 'bar', 'foo should not be equal to bar') // [!code ++]
2828+ })
2929+}
3030+```
3131+:::
3232+533## assert
634735- **Type:** `(expression: any, message?: string) => asserts expression`
+4
docs/guide/in-source.md
···152152153153Reference to [`examples/in-source-test`](https://github.com/vitest-dev/vitest/tree/main/examples/in-source-test) for the full example.
154154155155+::: warning
156156+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.
157157+:::
158158+155159## Notes
156160157161This feature could be useful for: