Access runtimeConfig from tests

Hey, I'm trying to access the runtime config from my tests, I've tried several things but nothing works.
await setup({
nuxtConfig: {
runtimeConfig: {
public: {
apiBasePath: 'http://localhost:3000/api/v1'
}
}
}
})

const config = useRuntimeConfig() // ReferenceError: useRuntimeConfig is not defined
await setup({
nuxtConfig: {
runtimeConfig: {
public: {
apiBasePath: 'http://localhost:3000/api/v1'
}
}
}
})

const config = useRuntimeConfig() // ReferenceError: useRuntimeConfig is not defined
import {useRuntimeConfig} from "#app";

describe('Login', async () => {
await setup({
nuxtConfig: {
runtimeConfig: {
public: {
apiBasePath: 'http://localhost:3000/api/v1'
}
}
}
})

const config = useRuntimeConfig() // Error: Failed to load url #app (resolved id: #app) in [...]/test/api/login.spec.ts. Does the file exist?
import {useRuntimeConfig} from "#app";

describe('Login', async () => {
await setup({
nuxtConfig: {
runtimeConfig: {
public: {
apiBasePath: 'http://localhost:3000/api/v1'
}
}
}
})

const config = useRuntimeConfig() // Error: Failed to load url #app (resolved id: #app) in [...]/test/api/login.spec.ts. Does the file exist?
3 Replies
conner
connerβ€’2y ago
/cc @danielroe
danielroe
danielroeβ€’2y ago
Would you try using nuxt-vitest?
Cetus πŸ”›πŸ”
Cetus πŸ”›πŸ”OPβ€’2y ago
hmm another module, it would be nice if they specified it in the doc The module has no documentation, how to use it? πŸ˜… nice... Error: Nuxt instance is unavailable!
const config = useRuntimeConfig({}, useNuxt())
const config = useRuntimeConfig({}, useNuxt())
sh*t, I was looking on npm, not on nuxt.com
Want results from more Discord servers?
Add your server