Last active
March 9, 2022 17:04
-
-
Save bsitruk/fca7a149f79f328805c07ff8865ebed4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Cypress.Commands.add('interceptOnce', (method, path, alias, status) => { | |
cy.intercept({ | |
method, | |
path, | |
times: 1, | |
}).as(alias); | |
if (status) { | |
return cy.wrap(() => | |
cy | |
.wait('@' + alias) | |
.its('response.statusCode') | |
.should('eq', status), | |
); | |
} | |
return cy.wrap(() => cy.wait('@' + alias)); | |
}); | |
// Usage | |
cy.interceptOnce('GET', 'some-url/', 'myAlias', 200).then(wait => { | |
// Do some work trigerring request to some-url | |
wait() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment