问题描述
我在nuxt.config.js中定义了私有运行时配置。作为玩笑测试的一部分,当我尝试测试具有运行时配置变量的方法时,它将引发未定义的变量error。有人可以帮我知道如何在玩笑测试中使用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()
})
})