首页 > 解决方案 > Cypress - 使用 Chrome 将函数传递给 .should()

问题描述

Cypress.IO 文档允许将函数传递给 should:https ://docs.cypress.io/api/commands/should.html#Function

如果我在无头或使用电子的情况下运行我的测试但在 Chrome 中失败,因为传递给函数的参数为​​空,则此方法有效。

我知道该元素存在,因为我之前测试过它。

cypress_runner.js:197677 AssertionError:目标不能为空或未定义。

describe('Cypress ', () => {

    it(`Works `, () => { 
      cy.get('span').should('have.length',25);
      cy.get('span').should(($span) => {
        expect($span).to.have.length(25);
      });
    });
  })

标签: cypress

解决方案


推荐阅读