我在 nuxt.config.js 中定义了私有(private)运行时配置。作为 Jest 测试的一部分,当我尝试测试具有运行时配置变量的方法时,它会抛出 undefined variable 错误。有人可以帮我知道如何在 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()
})
})
关于vue.js - 如何在 Jest 测试中使用 nuxt 运行时配置变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63616768/