Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js 如何在Jest测试中使用nuxt运行时配置变量_Vue.js_Jestjs_Vue Test Utils_Nuxtjs - Fatal编程技术网

Vue.js 如何在Jest测试中使用nuxt运行时配置变量

Vue.js 如何在Jest测试中使用nuxt运行时配置变量,vue.js,jestjs,vue-test-utils,nuxtjs,Vue.js,Jestjs,Vue Test Utils,Nuxtjs,我在nuxt.config.js中定义了私有运行时配置。作为jest测试的一部分,当我尝试测试一个具有运行时配置变量的方法时,它会抛出一个未定义的变量错误。有人能帮我知道如何在jest测试中使用nuxt运行时配置吗。只需提供模拟,如下所示: import { mount } from '@vue/test-utils' import MyComponent from '@/components/MyComponent.vue' describe('MyComponent', () =>

我在nuxt.config.js中定义了私有运行时配置。作为jest测试的一部分,当我尝试测试一个具有运行时配置变量的方法时,它会抛出一个未定义的变量错误。有人能帮我知道如何在jest测试中使用nuxt运行时配置吗。

只需提供模拟,如下所示:

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()
    })
})

只需提供模拟,如下所示:

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()
    })
})

我已经成功地模拟了其他全局属性,比如$fireStore,但是由于某些原因,$config似乎不起作用。仍然抛出“无法读取未定义的环境”错误。我已经成功地模拟了其他全局属性,如$fireStore,但是$config由于某些原因似乎不起作用。仍然抛出“无法读取未定义环境”错误。