Created
February 21, 2021 19:08
-
-
Save bahmutov/bd3220a9846918fee023ae85acc239a0 to your computer and use it in GitHub Desktop.
Example anchor ping stub in Cypress
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
```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