forked from cypress-io/cypress-example-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cypress-on-spec.js
33 lines (29 loc) · 1.06 KB
/
cypress-on-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/// <reference types="cypress" />
describe('Cypress.on window:before:load', () => {
// @see https://on.cypress.io/catalog-of-events
// let's use "window:before:load" to automatically
// attach mock Analytics method to the application's "window" object
Cypress.on('window:before:load', (win) => {
win.Analytics = {
sendEvent: cy.stub().as('sendEvent'),
}
})
it('sends events', () => {
cy.visit('index.html')
cy.get('button#click-me').click().click()
cy.get('@sendEvent').should('be.calledTwice')
.invoke('reset') // reset the stub counter
cy.get('button#click-me').click()
cy.get('@sendEvent').should('be.calledOnceWithExactly', 'click', 'button#click-me')
})
it('sends more events', () => {
cy.visit('index.html')
cy.get('button#click-me').click()
// if we do not precise value for one of the arguments
// we can "skip" it but make sure it is still a string
// using Sinon matchers
//
cy.get('@sendEvent').should('be.calledOnceWith',
Cypress.sinon.match.string, 'button#click-me')
})
})