簡體   English   中英

如何在 Jest 測試中使用 nuxt 運行時配置變量

[英]How to use nuxt runtime config variables in Jest tests

我在 nuxt.config.js 中定義了私有運行時配置。 作為玩笑測試的一部分,當我嘗試測試具有運行時配置變量的方法時,它會拋出一個未定義的變量錯誤。 有人可以幫助我知道如何在玩笑測試中使用 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()
    })
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM