Skip to content

Commit

Permalink
Better name cy.intercept aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
wlsf82 committed Jan 19, 2024
1 parent 3f75da0 commit eb9587f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions cypress/e2e/playground.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ describe('Cypress Playground', () => {
'GET',
'https://jsonplaceholder.typicode.com/todos/1',
{ statusCode: 500 }
).as('getTodo')
).as('serverFailure')
cy.contains('#intercept button', 'Get TODO').click()
cy.wait('@getTodo')
cy.wait('@serverFailure')
.its('response.statusCode')
.should('be.equal', 500)
cy.contains(
Expand All @@ -133,9 +133,9 @@ describe('Cypress Playground', () => {
'GET',
'https://jsonplaceholder.typicode.com/todos/1',
{ forceNetworkError: true }
).as('getTodo')
).as('networkError')
cy.contains('#intercept button', 'Get TODO').click()
cy.wait('@getTodo')
cy.wait('@networkError')
cy.contains(
'#intercept .error span',
'Oops, something went wrong. Check your internet connection, refresh the page, and try again.'
Expand Down
8 changes: 4 additions & 4 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ <h2>
<br>
<code>cy.wait('@getTodo')</code>
<p>With the <code>cy.intercept()</code> command, you could even simulate an API failure.</p>
<p>For example: <code>cy.intercept('GET', 'https://api.example.com/todos/1', { statusCode: 500 }).as('getTodo')</code>.</p>
<p>For example: <code>cy.intercept('GET', 'https://api.example.com/todos/1', { statusCode: 500 }).as('serverFailure')</code>.</p>
<p>Then, you could assert that it has really failed.</p>
<p>For example: <code>cy.wait('@getTodo').its('response.statusCode').should('be.equal', 500)</code>.</p>
<p>For example: <code>cy.wait('@serverFailure').its('response.statusCode').should('be.equal', 500)</code>.</p>
<p>And maybe, even assert that certain fallback element has been displayed.</p>
<p>For example: <code>cy.contains('.error', 'Oops, something went wrong.').should('be.visible')</code>.</p>
<p>Finally, with the <code>cy.intercept()</code>command, you could force a network error, to test how your web app would behave if there were no internet available, for instance.</p>
<p>For example: <code>cy.intercept('GET', 'https://api.example.com/todos/1', { forceNetworkError: true }).as('getTodo')</code>.</p>
<p>For example: <code>cy.intercept('GET', 'https://api.example.com/todos/1', { forceNetworkError: true }).as('networkError')</code>.</p>
<p>Then, you could wait for such a failure.</p>
<p>For example: <code>cy.wait('@getTodo')</code>.</p>
<p>For example: <code>cy.wait('@networkError')</code>.</p>
<p>And then, you could even assert that certain fallback element has been displayed.</p>
<p>For example: <code>cy.contains('.error', "Oops, it seems you don't have internet connection.").should('be.visible')</code>.</p>
<button>Get TODO</button>
Expand Down

0 comments on commit eb9587f

Please sign in to comment.