suchen

Heim  >  Fragen und Antworten  >  Hauptteil

Wie stoppt man die Funktionsausführung im Test?

Wie teste ich diesen Fall?

Ich habe eine Variable in den Einstellungen:

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

Während der Test läuft, wird die Funktion await isContinuing(address) ausgeführt. Wie kann ich dafür sorgen, dass eine Funktion nicht ausgeführt wird, während der Test läuft? Mein Test hat eine undefinierte Wrapper-Variable

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粉348915572363 Tage vor432

Antworte allen(1)Ich werde antworten

  • 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)
    }
    

    Antwort
    0
  • StornierenAntwort