Skip to content

Commit

Permalink
docs: add toHaveBeenCalledBefore/toHaveBeenCalledAfter
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Nov 13, 2024
1 parent c10728d commit 0608b91
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions docs/api/expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,44 @@ test('spy function', () => {
})
```

## toHaveBeenCalledBefore <Version>2.2.0</Version> {#tohavebeencalledbefore}

- **Type**: `(mock: MockInstance, failIfNoFirstInvocation?: boolean) => Awaitable<void>`

This assertion checks if a `Mock` was called before another `Mock`.

```ts
test('calls mock1 before mock2', () => {
const mock1 = vi.fn()
const mock2 = vi.fn()

mock1()
mock2()
mock1()

expect(mock1).toHaveBeenCalledBefore(mock2)
})
```

## toHaveBeenCalledAfter <Version>2.2.0</Version> {#tohavebeencalledafter}

- **Type**: `(mock: MockInstance, failIfNoFirstInvocation?: boolean) => Awaitable<void>`

This assertion checks if a `Mock` was called after another `Mock`.

```ts
test('calls mock1 after mock2', () => {
const mock1 = vi.fn()
const mock2 = vi.fn()

mock2()
mock1()
mock2()

expect(mock1).toHaveBeenCalledAfter(mock2)
})
```

## toHaveBeenCalledExactlyOnceWith <Version>2.2.0</Version> {#tohavebeencalledexactlyoncewith}

- **Type**: `(...args: any[]) => Awaitable<void>`
Expand Down

0 comments on commit 0608b91

Please sign in to comment.