Skip to content

Instantly share code, notes, and snippets.

@bsitruk
Last active March 9, 2022 17:04
Show Gist options
  • Save bsitruk/fca7a149f79f328805c07ff8865ebed4 to your computer and use it in GitHub Desktop.
Save bsitruk/fca7a149f79f328805c07ff8865ebed4 to your computer and use it in GitHub Desktop.
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