2

我在 nuxt.config.js 中定义了私有运行时配置。作为开玩笑测试的一部分,当我尝试测试具有运行时配置变量的方法时,它会引发 undefined variable error 。有人可以帮我知道如何在开玩笑测试中使用 nuxt 运行时配置。

4

1 回答 1

3

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

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()
    })
})
于 2020-10-12T19:26:32.570 回答