Skip to content

How do you mock a module multiple times (now) ? #4124

Answered by sheremet-va
RossRogers asked this question in Q&A
Discussion options

You must be logged in to vote

You can use vi.hoisted instead:

const api = vi.hoisted(() => vi.fn())
vi.mock("./path.js". () => ({
  api
})
api.mockReturnValue(42)
api.mockReturnValue(0)

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@RossRogers
Comment options

@AmielCyber
Comment options

@oanaOM
Comment options

@breathTake
Comment options

@sheremet-va
Comment options

Answer selected by RossRogers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants