Skip to content
Discussion options

You must be logged in to vote

The vi.mock(import('./example.js') is just syntax sugar for typescript. You can write the same code without import() as:

- vi.mock(import('./example.js'), async (importOriginal) => {
-  const originalModule = await importOriginal()
+ vi.mock('./example.js', async (importOriginal) => {
+  const originalModule: typeof import('./example.js') = await importOriginal()
  return {
    answer: vi.fn(originalModule.answer),
    variable: 'mock',
  }
})

Though personally I would just disable that ESLint rule from any test files.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@brannonh
Comment options

Answer selected by brannonh
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
2 participants