Skip to content
Discussion options

You must be logged in to vote

Hi @benedictleejh,

For anything in your server/ dir, you'll want the nuxt environment. The node env is totally separate, knows nothing about Nuxt/Nitro. It's just for plain utils. And nope, there's no separate nitro env, as far as I know. It's all part of the nuxt one.

I usually structure it like this:

test/
├── nuxt/
│   └── server/
│       └── my-api.spec.ts   # <-- 'nuxt' env
└── unit/
    └── some-util.spec.ts  # <-- 'node' env

So for testing an API route, you can just do:

// test/nuxt/server/my-api.spec.ts
import { describe, it, expect } from 'vitest'

it('works', async () => {
  const result = await $fetch('/api/my-route')
  expect(result).toBeDefined()
})

Basically, if the code nee…

Replies: 1 comment 1 reply

Comment options

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

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