I am testing pinia store in nuxt3
app.
Inside setup()
of store I'm using useRuntimeConfig
to get initial value for counter from public config variables and I got this error ReferenceError: useRuntimeConfig is not defined
don't know how to solve it
// store/counter.ts
...
state: () => {
const runtimeConfig = useRuntimeConfig()
const count = runtimeConfig.public.count
return {
...
count
...
}
},
...
code
// store/counter.test.ts
import { fileURLToPath } from 'node:url'
import { describe, expect, it, beforeEach } from 'vitest'
import { setActivePinia, createPinia } from 'pinia'
import { useCounter } from './counter'
import { setup } from '@nuxt/test-utils'
await setup({
rootDir: fileURLToPath(new URL('../', import.meta.url)),
server: true,
browser: true,
})
describe('Counter Store', () => {
beforeEach(() => {
// creates a fresh pinia and make it active so it's automatically picked
// up by any useStore() call without having to pass it to it:
// `useStore(pinia)`
setActivePinia(createPinia())
})
it('increments', () => {
const counter = useCounter()
expect(counter.n).toBe(0)
counter.increment()
expect(counter.n).toBe(1)
})
it('increments by amount', () => {
const counter = useCounter()
counter.increment(10)
expect(counter.n).toBe(10)
})
})