Skip to content

Instantly share code, notes, and snippets.

@bahmutov
Created February 21, 2021 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bahmutov/bd3220a9846918fee023ae85acc239a0 to your computer and use it in GitHub Desktop.
Save bahmutov/bd3220a9846918fee023ae85acc239a0 to your computer and use it in GitHub Desktop.
Example anchor ping stub in Cypress
```js
/// <reference types="Cypress" />
describe('intercept', () => {
it('stubs anchor ping', () => {
cy.visit('/')
cy.intercept({
method: 'POST',
pathname: '/track'
}, {}).as('ping')
cy.get('a[ping]').click()
cy.location('pathname').should('equal', 'page2.html')
cy.wait('@ping').its('request.headers').should('deep.include', {
'ping-from': `${Cypress.config('baseUrl')}/`,
'ping-to': `${Cypress.config('baseUrl')}/page2.html`,
})
})
})
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment