使用 cy.intercept() 拦截(和存根)几个网络请求(到谷歌标签管理器),但希望在我的测试中尽早进行测试,然后再期望它们被调用。
我将如何测试我正在拦截的两条路线haven't被叫了吗?
Thanks!
您可以利用cy.spy
命令:
cy.intercept('/my-route', cy.spy().as('myRequest'));
// later in the test
cy.get('@myRequest').should('not.have.been.called'); // not yet intercepted
// something triggers the API call
cy.get('@myRequest').should('have.been.calledOnce'); // now is intercepted
See: https://docs.cypress.io/api/commands/spy https://docs.cypress.io/api/commands/spy
致谢:https://glebbahmutov.com/blog/cypress-tips-and-tricks/#check-if-the-network-call-has-not-been-made https://glebbahmutov.com/blog/cypress-tips-and-tricks/#check-if-the-network-call-has-not-been-made
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)