Skip to content

How to check mocked function is called? #5547

Discussion options

You must be logged in to vote

And I want to check that apolloQuery has been called for example. How would I do this?

It could be something like this:

- apolloQuery: () => { return Promise.resolve(); }
+ apolloQuery: vi.fn(() => { return Promise.resolve(); })
import { apolloQuery } from "@/api";

vi.mock("@/api", ...);

it("...", () => {
  // do something with apolloQuery ...

  // then assert
  expect(apolloQuery).toHaveBeenCalled()  
})

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by steven-twerdochlib
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants