Skip to content

How to mock a module multiple times? #1255

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

You must be logged in to vote

You can import it and change the returned value:

import { cosmiconfig } from 'cosmiconfig'

vi.mocked(cosmiconfig).mockReturnValue({
  search: () => Promise.reject(null)
})

vi.mocked is just a typehint, btw. It's noop.

Replies: 5 comments 11 replies

Comment options

You must be logged in to vote
9 replies
@tal-rofe
Comment options

@sheremet-va
Comment options

@tal-rofe
Comment options

@sheremet-va
Comment options

@tal-rofe
Comment options

Answer selected by tal-rofe
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@sheremet-va
Comment options

@adaptably
Comment options

Comment options

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