[英]How to use nuxt runtime config variables in Jest tests
I've private runtime config defined in nuxt.config.js.我在 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 .
有人可以帮助我知道如何在玩笑测试中使用 nuxt 运行时配置。
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()
})
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.