Cypress:如果其()函数没有超时,如何传递

Cypress:如果其()函数没有超时,如何传递,cypress,Cypress,我有一个测试,我想知道一个窗口属性在一个任意的超时时间后没有被设置 因此,在伪代码中: 这是“味精1”{ 超时:3000 }.should.timeoutIn3000 换句话说,如果达到3000ms超时,则测试通过。如果窗口属性msg_1在3000ms之前出现,则测试应失败 可能吗?我可能错过了这里显而易见的东西 谢谢策略可能是测试,等等,再次测试 it('does not see the message', () => { cy.visit('http://example.com'

我有一个测试,我想知道一个窗口属性在一个任意的超时时间后没有被设置

因此,在伪代码中:

这是“味精1”{ 超时:3000 }.should.timeoutIn3000 换句话说,如果达到3000ms超时,则测试通过。如果窗口属性msg_1在3000ms之前出现,则测试应失败

可能吗?我可能错过了这里显而易见的东西


谢谢

策略可能是测试,等等,再次测试

it('does not see the message', () => {

  cy.visit('http://example.com').then(win => {
    setTimeout(() => {
      win.msg_1 = 'hi'
    }, 1000)
    
  })

  cy.window().then(win => expect(win.msg_1).to.eq(undefined))  // passes
  cy.wait(3000)
  cy.window().then(win => expect(win.msg_1).to.eq(undefined))  // fails

})

策略可能是测试,等等,再次测试

it('does not see the message', () => {

  cy.visit('http://example.com').then(win => {
    setTimeout(() => {
      win.msg_1 = 'hi'
    }, 1000)
    
  })

  cy.window().then(win => expect(win.msg_1).to.eq(undefined))  // passes
  cy.wait(3000)
  cy.window().then(win => expect(win.msg_1).to.eq(undefined))  // fails

})

好的,根据@EQQ的有用回复,我发现了以下作品:

    // This will pass if it is not there
    cy.window().then(win => expect(win.msg_1).to.eq(undefined))

    // Wait for the timeout and test again
    cy.window().wait(3000).then(win => {
      expect(win.msg_1).to.eq(undefined)
    })
并作为自定义命令:

    /**
     * Use to test that a window property does NOT turn up
     * within the specified time period
     */
    Cypress.Commands.add("notIts", (prop, timeout) => {
      cy.window().then(win => expect(win[prop]).to.eq(undefined))
      cy.window().wait(timeout).then(win => {
        expect(win[prop]).to.eq(undefined)
      })
    });
用法如下:

    cy.notIts('msg_1', 3000)
也许这不是一个好名字,但无论如何,这对我来说很有用

谢谢!
Murray

好的,在@EQQ的有益回复之后,我发现了以下作品:

    // This will pass if it is not there
    cy.window().then(win => expect(win.msg_1).to.eq(undefined))

    // Wait for the timeout and test again
    cy.window().wait(3000).then(win => {
      expect(win.msg_1).to.eq(undefined)
    })
并作为自定义命令:

    /**
     * Use to test that a window property does NOT turn up
     * within the specified time period
     */
    Cypress.Commands.add("notIts", (prop, timeout) => {
      cy.window().then(win => expect(win[prop]).to.eq(undefined))
      cy.window().wait(timeout).then(win => {
        expect(win[prop]).to.eq(undefined)
      })
    });
用法如下:

    cy.notIts('msg_1', 3000)
也许这不是一个好名字,但无论如何,这对我来说很有用

谢谢!
默里

感谢您的回复。这很有帮助。我发现当我使用代码时,Cypress并没有等待。如果我将其记录在控制台中,则第二个测试将在第一个测试之后立即运行。看看这些文件,它应该是有效的。然而,请看下面我最终做了什么。再次感谢你的帮助,默里。默里,你做错了什么,这确实需要等待。谢谢理查德。我会回去看看可能是什么问题。我在cypress Cumber中使用它,但我看不出这会是一个什么问题。我所经历的是一个控制台日志在等待前后同时出现-第二次没有3秒的延迟。像cy.wait这样的命令是异步的。测试中的所有同步命令,如console.log,在命令执行前等待运行的任一侧。感谢您的回复。这很有帮助。我发现当我使用代码时,Cypress并没有等待。如果我将其记录在控制台中,则第二个测试将在第一个测试之后立即运行。看看这些文件,它应该是有效的。然而,请看下面我最终做了什么。再次感谢你的帮助,默里。默里,你做错了什么,这确实需要等待。谢谢理查德。我会回去看看可能是什么问题。我在cypress Cumber中使用它,但我看不出这会是一个什么问题。我所经历的是一个控制台日志在等待前后同时出现-第二次没有3秒的延迟。像cy.wait这样的命令是异步的。测试中的所有同步命令,如console.log在命令执行前等待运行的任一侧。