How to use nuxt runtime config variables in Jest tests

Viewed 832

I've private runtime config defined in nuxt.config.js. As part of jest tests, when I'm trying to test a method which has runtime config variables, it's throwing a undefined variable error . Could someone please help me know how to use the nuxt runtime config in jest tests .

1 Answers

Just provide mocks, like this:

import { mount } from '@vue/test-utils'
import MyComponent from '@/components/MyComponent.vue'

describe('MyComponent', () => {
    test('is a Vue instance', () => {
        const wrapper = mount(MyComponent, {
            mocks: {
                $config: {
                    MyProp: 'some value'
                }
             }
        })
        expect(wrapper).toBeTruthy()
    })
})
Related