Vue.js 如何在Jest测试中使用nuxt运行时配置变量
我在nuxt.config.js中定义了私有运行时配置。作为jest测试的一部分,当我尝试测试一个具有运行时配置变量的方法时,它会抛出一个未定义的变量错误。有人能帮我知道如何在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', () =>
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由于某些原因似乎不起作用。仍然抛出“无法读取未定义环境”错误。