Skip to content

Commit

Permalink
Update Vitest Typescript documentation (closes #649)
Browse files Browse the repository at this point in the history
  • Loading branch information
keeganwitt committed Oct 9, 2023
1 parent 1f88101 commit ed64b54
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions website/docs/getting-started/setup.md
Expand Up @@ -60,38 +60,28 @@ export default defineConfig({

To use Vitest with TypeScript, create a file named `jest-extended.d.ts` with the content below in addition to the setup above.

```typescript
/// <reference types="vitest" />

export interface CustomMatchers<R> extends Record<string, any> {
toHaveBeenCalledAfter(
mock: jest.MockInstance<any, any[]> | import('vitest').MockInstance<any, any[]>,
failIfNoFirstInvocation?: boolean,
): R;

toHaveBeenCalledBefore(
mock: jest.MockInstance<any, any[]> | import('vitest').MockInstance<any, any[]>,
failIfNoSecondInvocation?: boolean,
): R;

toHaveBeenCalledExactlyOnceWith(...args: unknown[]): R;
}
```

For Vitest >= 0.31.0, append the content below to the new file.
#### Vitest >= 0.31.0

```typescript
import type CustomMatchers from 'jest-extended';
import 'vitest';

declare module 'vitest' {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface Assertion<T = any> extends CustomMatchers<T> {}
interface AsymmetricMatchersContaining<T = any> extends CustomMatchers<T> {}
interface ExpectStatic extends CustomMatchers<T> {}
}
```

For Vitest < 0.31.0, append the content below to the new file.
#### Vitest < 0.31.0

```typescript
declare namespace Vi {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface AsymmetricMatchersContaining extends CustomMatchers<any> {}
import type CustomMatchers from 'jest-extended';
import 'vi';

declare module 'vi' {
interface Assertion<T = any> extends CustomMatchers<T> {}
interface AsymmetricMatchersContaining<T = any> extends CustomMatchers<T> {}
interface ExpectStatic extends CustomMatchers<T> {}
}
```

0 comments on commit ed64b54

Please sign in to comment.