Skip to content

How to mock optional import in vitest #6344

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

You must be logged in to vote

You need to specify a fallback in the config because the error is controlled by Vite, not Vitest:

https://vitest.dev/guide/mocking.html#virtual-modules

You need to tell Vite that module exists otherwise it will fail during parsing

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@jkmcclinton
Comment options

@sheremet-va
Comment options

@jkmcclinton
Comment options

@sheremet-va
Comment options

Answer selected by jkmcclinton
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