I am learning and coding a Nuxt application example and try to test all files. Once is left:
% Coverage report from v8
----------------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------------------------|---------|----------|---------|---------|-------------------
...
nuxt-boil/server/api | 0 | 0 | 0 | 0 |
env.ts | 0 | 0 | 0 | 0 | 1-4
server/api/env.ts
export default defineEventHandler(async (event) => {
const { NUXT_API_SECRET } = process.env
return NUXT_API_SECRET
})
tests/server/api/env.test.ts
import { setup } from '@nuxt/test-utils'
import { $fetch } from '@nuxt/test-utils/e2e'
describe('route: /api/env', async () => {
await setup({
server: true
})
test('return env NUXT_API_SECRET', async () => {
const { data } = await useAsyncData(() => $fetch('/api/env'))
expect(data.value).toEqual(import.meta.env.NUXT_API_SECRET)
})
})
Test result is
...
✓ tests/server/api/env.test.ts (1) 12868ms
I tried to find different solutions for testing routes.
Could you provide tests for 100% coverage (v8/istanbul)? I think I have (as usual) a basic understanding problem :-)