mockNuxtImport() is a macro and it did not get transpiled
Writing an example test
Throws the error
import { describe, expect, it, vi } from 'vitest'
import { mockNuxtImport } from '@nuxt/test-utils/runtime'
// Define the mock API
const mockApi = vi.hoisted(() => ({
worklog: {
list: vi.fn(),
},
}))
// Mock useNuxtApp
mockNuxtImport('useNuxtApp', () => {
return () => ({
$api: mockApi,
})
})
// Example test
describe('MyComponent', () => {
it('should call worklog.list', async () => {
mockApi.worklog.list.mockResolvedValue([{ id: 1, title: 'Test' }])
const result = await mockApi.worklog.list()
expect(result).toEqual([{ id: 1, title: 'Test' }])
expect(mockApi.worklog.list).toHaveBeenCalled()
})
})import { describe, expect, it, vi } from 'vitest'
import { mockNuxtImport } from '@nuxt/test-utils/runtime'
// Define the mock API
const mockApi = vi.hoisted(() => ({
worklog: {
list: vi.fn(),
},
}))
// Mock useNuxtApp
mockNuxtImport('useNuxtApp', () => {
return () => ({
$api: mockApi,
})
})
// Example test
describe('MyComponent', () => {
it('should call worklog.list', async () => {
mockApi.worklog.list.mockResolvedValue([{ id: 1, title: 'Test' }])
const result = await mockApi.worklog.list()
expect(result).toEqual([{ id: 1, title: 'Test' }])
expect(mockApi.worklog.list).toHaveBeenCalled()
})
})Throws the
mockNuxtImport() is a macro and it did not get transpiled. This may be an internal bug of @nuxt/test-utilsmockNuxtImport() is a macro and it did not get transpiled. This may be an internal bug of @nuxt/test-utils