#Access runtimeConfig from tests

7 messages · Page 1 of 1 (latest)

median oar
#

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
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?
rich stone
#

/cc @vale cobalt

vale cobalt
#

Would you try using nuxt-vitest?

median oar
#

hmm another module, it would be nice if they specified it in the doc

median oar
#

The module has no documentation, how to use it? 😅

#

nice... Error: Nuxt instance is unavailable!

#
const config = useRuntimeConfig({}, useNuxt())