【发布时间】:2021-06-07 10:52:01
【问题描述】:
希望你一切顺利。 我目前正在将 cypress 升级到 7.0。 (更准确地说是 v7.4.0) 我对拦截调用的覆盖有疑问。
赛普拉斯团队似乎致力于解决最重要的问题https://github.com/cypress-io/cypress/pull/14543(问题:https://github.com/cypress-io/cypress/issues/9302),但它对我不起作用。
BREAKING CHANGE: Request handlers supplied to cy.intercept are now matched starting with the most-recently-defined request interceptor. This allows users to override request handlers by calling cy.intercept again. This matches the previous behavior that was standard in cy.route.
我的第一个电话处理 2xx 响应(我自己模拟)
cy.intercept('GET', 'sameUrl', {
statusCode: 2xx
}
但是我需要另一个具有相同 url 但状态不同的拦截:
cy.intercept('GET', 'sameUrl', {
statusCode: 4xx
}
我尝试使用 middleware :
A new option, middleware, has been added to the RouteMatcher type. If true, the supplied request handler will be called before any non-middleware request handlers.
cy.intercept({ method: 'GET', url: 'sameUrl', middleware: true}, req => {
req.continue(res => {
res.statusCode = 4xx
});
}
但它不起作用,第一个拦截总是被调用的那个。如果您知道我做错了什么/另一种解决方案,我会全力以赴!
【问题讨论】:
标签: javascript testing cypress e2e-testing