Не уверен, что есть какой-то канонический способ, но вы можете обезопасить патч XMLHttpRequest
API и добавить >= 500
статусных ответов.
Если ваше приложение использует Fetch API, SendBeacon или что-то еще, вы можете сделать что-то подобное.
// put this in support/index.js
Cypress.on('window:before:load', win => {
const origSend = win.XMLHttpRequest.prototype.send;
win.XMLHttpRequest.prototype.send = function () {
// deferring because your app may be using an abstraction (jquery),
// which may set this handler *after* it sets the `send` handler
setTimeout(() => {
const origHandler = this.onreadystatechange;
this.onreadystatechange = function () {
if ( this.readyState === 4 && this.status >= 500 ) {
throw new Error(`Server responded to "${this.url}" with ${this.status}`);
}
if ( origHandler ) {
return origHandler.apply(this, arguments);
}
};
return origSend.apply(this, arguments);
});
};
});
WTBS, это не очень полезно, потому что ваше приложение может захотеть обработать этот 500
вместо этого, в то время как это предотвратит это.
Лучшее решение - убедиться, что ваше приложение просто генерирует необработанные 500 ответов.