首页  >  问答  >  正文

如何停止测试中的函数执行?

如何测试这个案例?

我在设置中有一个变量:

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 天前342

全部回复(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
  • 取消回复