赛普拉斯 |有没有办法测试我们写的测试

Cypress | Is there a way to test the tests we have written

我想测试我们编写的测试。例如,如果开发人员使用 type 命令创建测试,例如:

cy.get('input').type('Hello, World')

我想测试这个 type() 是否有 log:false 的选项。如果没有 log:false 选项则测试失败。

代码应如下所示:

cy.get('input').type('Hello, World', { log: false })

有人使用 Cypress 实现过这个吗? 运行 测试来测试我们的测试。

不完全是你问的,但是

/cypress/support/index.js

Cypress.Commands.overwrite('type', (originalFn, text, options) => {

  // enforce no-log policy
  return originalFn(text, { ...options, log: false })
})

或者如果你喜欢指手画脚

Cypress.Commands.overwrite('type', (originalFn, text, options) => {

  if (!options.log || options.log) {
    throw "  No logging allowed on .type()"
  }

  return originalFn(text, options)
})