N
Nuxt6mo ago
Chris

Reuse import mocks possible?

I use the following code to setup a mock for a composable called 'useComposable':
const { useComposableMock } = vi.hoisted(() => {
return {
useComposableMock: vi.fn().mockImplementation(() => {
return {}
})
}
})

mockNuxtImport('useComposable', () => {
return useComposableMock
})
const { useComposableMock } = vi.hoisted(() => {
return {
useComposableMock: vi.fn().mockImplementation(() => {
return {}
})
}
})

mockNuxtImport('useComposable', () => {
return useComposableMock
})
Such that I can alter the mock within each test like this
useComposableMock.mockImplementation(() => console.log('banana'))
useComposableMock.mockImplementation(() => console.log('banana'))
I tried reusing the setup code for creating the mock as I found it to be a lot of boilerplate code. However, I'm only able to setup the mock within the test itself. Is there a way in which I can import a default mock 'useComposableMock' that I can mock in my tests?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server