Skip to content

Commit

Permalink
Merge branch 'main' into improve-includeSameMembers-error-message
Browse files Browse the repository at this point in the history
  • Loading branch information
rluvaton committed Oct 25, 2023
2 parents 92b479b + c8a3113 commit f51f475
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 24 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,11 @@
# jest-extended

## 4.0.2

### Patch Changes

- 1f88101: Mark 2nd param of toHaveBeenCalledBefore and toHaveBeenCalledAfter optional

## 4.0.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "jest-extended",
"version": "4.0.1",
"version": "4.0.2",
"description": "Additional Jest matchers",
"main": "dist/index.js",
"types": "types/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions types/index.d.ts
Expand Up @@ -148,7 +148,7 @@ interface CustomMatchers<R> extends Record<string, any> {
* @param {Mock} mock
* @param {boolean} [failIfNoSecondInvocation=true]
*/
toHaveBeenCalledBefore(mock: jest.MockInstance<any, any[]>, failIfNoSecondInvocation: boolean): R;
toHaveBeenCalledBefore(mock: jest.MockInstance<any, any[]>, failIfNoSecondInvocation?: boolean): R;

/**
* Use `.toHaveBeenCalledAfter` when checking if a `Mock` was called after another `Mock`.
Expand All @@ -158,7 +158,7 @@ interface CustomMatchers<R> extends Record<string, any> {
* @param {Mock} mock
* @param {boolean} [failIfNoFirstInvocation=true]
*/
toHaveBeenCalledAfter(mock: jest.MockInstance<any, any[]>, failIfNoFirstInvocation: boolean): R;
toHaveBeenCalledAfter(mock: jest.MockInstance<any, any[]>, failIfNoFirstInvocation?: boolean): R;

/**
* Use `.toHaveBeenCalledOnce` to check if a `Mock` was called exactly one time.
Expand Down
60 changes: 42 additions & 18 deletions website/docs/getting-started/setup.md
Expand Up @@ -60,38 +60,62 @@ 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.

#### Vitest >= 0.31.0

```typescript
/// <reference types="vitest" />
import type CustomMatchers from 'jest-extended';
import 'vitest';

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

export interface CustomMatchers<R> extends Record<string, any> {
toHaveBeenCalledAfter(
mock: jest.MockInstance<any, any[]> | import('vitest').MockInstance<any, any[]>,
failIfNoFirstInvocation?: boolean,
): R;
This can be combined with matchers from other dependencies or your own custom matchers. Here's an example of a custom matcher.

toHaveBeenCalledBefore(
mock: jest.MockInstance<any, any[]> | import('vitest').MockInstance<any, any[]>,
failIfNoSecondInvocation?: boolean,
): R;
```typescript
import type CustomMatchers from 'jest-extended';
import 'vitest';

toHaveBeenCalledExactlyOnceWith(...args: unknown[]): R;
interface MyCustomMatchers {
toBeFoo(): any;
}

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

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

```typescript
declare module 'vitest' {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
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> {}
}
```

For Vitest < 0.31.0, append the content below to the new file.
This can be combined with matchers from other dependencies or your own custom matchers. Here's an example of a custom matcher.

```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';

interface MyCustomMatchers {
toBeFoo(): any;
}

declare module 'vi' {
interface Assertion<T = any> extends CustomMatchers<T>, MyCustomMatchers {}
interface AsymmetricMatchersContaining<T = any> extends CustomMatchers<T>, MyCustomMatchers {}
interface ExpectStatic extends CustomMatchers, MyCustomMatchers {}
}
```
6 changes: 3 additions & 3 deletions website/yarn.lock
Expand Up @@ -6243,9 +6243,9 @@ postcss-zindex@^5.1.0:
integrity sha512-fgFMf0OtVSBR1va1JNHYgMxYk73yhn/qb4uQDq1DLGYolz8gHCyr/sesEuGUaYs58E3ZJRcpoGuPVoB7Meiq9A==

postcss@^8.3.11, postcss@^8.4.14, postcss@^8.4.17, postcss@^8.4.21:
version "8.4.30"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.30.tgz#0e0648d551a606ef2192a26da4cabafcc09c1aa7"
integrity sha512-7ZEao1g4kd68l97aWG/etQKPKq07us0ieSZ2TnFDk11i0ZfDW2AwKHYU8qv4MZKqN2fdBfg+7q0ES06UA73C1g==
version "8.4.31"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.31.tgz#92b451050a9f914da6755af352bdc0192508656d"
integrity sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==
dependencies:
nanoid "^3.3.6"
picocolors "^1.0.0"
Expand Down

0 comments on commit f51f475

Please sign in to comment.