首頁  >  問答  >  主體

如何停止測試中的函數執行?

如何測試這個案例?

我在設定中有一個變數:

setup() {
      const address = `${process.env.VAR_ENV}`
  onMounted(async () => {
        const stop = await isContinuing(address)

測試執行時,函數 await isContinuing(address) 正在執行。如何在測試運行時使函數運行?

我的測試未定義包裝變數

beforeEach(() => {
  wrapper = shallowMount(App, {
  })
})

describe('Dashboard', () => {
  it('test to verify if initial section.', () => {
    const expected = 0
    expect(wrapper.findComponent({ ref: 'section' }).element.value).toBe(
      expected
    )
  })

P粉348915572P粉348915572244 天前340

全部回覆(1)我來回復

  • P粉917406009

    P粉9174060092024-02-18 10:10:35

    Jest(我假設大多數測試框架)將 NODE_ENV 環境變數設為 test。因此,您可以使用簡單的 if 語句來不在測試中執行某些操作:

    if(process.env.NODE_ENV !== 'test') {
      const stop = await isContinuing(address)
    }
    

    回覆
    0
  • 取消回覆