-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add option to fail on 5xx errors (#76)
### fail on 5xx By default, the network calls might fail and the test happily continues. You can make the idle spy fail if any of the matching network calls return 4xx or 5xx errors. These classes of error status code have their own flag to enable. ```js // fail the test if any of the matching calls // returns a 5xx status code cy.waitForNetworkIdlePrepare({ method: '*', alias: 'all', pattern: '**', failOn5xx: true, }) ```
- Loading branch information
Showing
7 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/// <reference path="../../src/index.d.ts" /> | ||
// @ts-check | ||
|
||
import '../..' | ||
|
||
// fails the test on 500 response code, but not on 401 | ||
it('fails the test when a request receives 500 status code', () => { | ||
cy.on('fail', (e) => { | ||
if (e.message.includes('failed with 500')) { | ||
console.log('expected error') | ||
return false | ||
} else { | ||
throw e | ||
} | ||
}) | ||
|
||
// fail the test if any of the matching calls | ||
// returns a 5xx status code | ||
cy.waitForNetworkIdlePrepare({ | ||
method: '*', | ||
alias: 'all', | ||
pattern: '**', | ||
failOn5xx: true, | ||
}) | ||
|
||
cy.visit('/fail-500') | ||
.wait(3000) | ||
.then(() => { | ||
// the network should have caught an 5xx error | ||
throw new Error('Should never get here') | ||
}) | ||
}) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<body> | ||
<p> | ||
This page makes a request that receives 500. It also makes another request | ||
that receives 401. | ||
</p> | ||
<script> | ||
setTimeout(() => { | ||
fetch('/status-401') | ||
}, 300) | ||
|
||
setTimeout(() => { | ||
fetch('/status-500') | ||
}, 800) | ||
</script> | ||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters