【问题标题】:cy.intercept is not a function Cypress testcy.intercept 不是 Cypress 测试的函数
【发布时间】:2021-03-10 13:53:57
【问题描述】:

我正在从赛普拉斯文档中复制代码并返回此错误 cy.intercept is not a function

我的代码直接来自文档...

describe('My First Test', () => {
  it('Visit Home Page', () => {
      cy.intercept('search/*', [{ item: 'Book 1' }, { item: 'Book 2' }]).as('getSearch')
  }
})

不知道为什么会这样?

【问题讨论】:

  • 您的系统上安装的 cypress 版本是什么?
  • "cypress": "^5.3.0",
  • 您必须升级到 v6.0,cy.intercept() 才能工作。
  • 它为您解决了问题吗?
  • 是的,谢谢!

标签: testing cypress


【解决方案1】:

请参阅intercept - history,该功能自 Cypress v5.1.0 起就可用,它只是称为cy.route2()(以防您不想升级)。

版本更改
6.0.0 将 cy.route2() 重命名为 cy.intercept()。
6.0.0 删除了 experimentalNetworkStubbing 选项并使其成为默认行为。
5.1.0 在experimentalNetworkStubbing 选项下增加了experimental cy.route2() 命令。

但是如果你保持在 v5.3.0,你将不得不添加

"experimentalNetworkStubbing": true

到 cypress.json。


版本 7.0.0

发布说明说

cy.route2() 以前别名为 cy.intercept()。现在别名 cy.route2() 已被删除。请将 cy.route2() 的用法更新为 cy.intercept()

【讨论】:

    猜你喜欢
    • 2021-09-03
    • 1970-01-01
    • 2021-12-13
    • 1970-01-01
    • 2021-11-10
    • 1970-01-01
    • 1970-01-01
    • 2021-11-05
    • 2019-05-06
    相关资源
    最近更新 更多