This repository was archived by the owner on Feb 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 188
/
Copy pathspec.js
72 lines (63 loc) · 2.34 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/// <reference types="cypress" />
/* eslint-disable-next-line no-unused-vars */
import { enterTodo, resetData, removeTodo } from '../../support/utils'
describe('Stubbing window.track', () => {
beforeEach(resetData)
// by default the "window.track" is called by the app
// on load, on new todo, and on removing todo
// and just prints the message using console.log
it('works on click', () => {
// visit the page
// stub "window.track"
// enter new todo
// confirm the stub "window.track" was called once
// with expected argument
// tip: use 'have.been.calledOnceWithExactly' assertion
})
it('tracks item delete', () => {
// visit the page
// stub "window.track"
// enter and remove new todo
// assert the stub "window.track" was called
// with expected arguments
})
it('resets the count', () => {
// add a couple of items
// confirm the stub was called N times
// reset the stub
// by invoking ".reset()" method
// trigger more events
// confirm the new number
})
it('adds stub after reload', () => {
// create a single stub with
// const trackStub = cy.stub().as('track')
// stub the window.track after cy.visit
// and after reload
// and then count the number of calls
})
it('works on load', () => {
// set up the stub when the window object exists
// but before any code loads
// see https://on.cypress.io/visit onBeforeLoad
// use Object.defineProperty(win, 'track', {...}) to
// get the "window.track = fn" assignment and call
// the cy.stub wrapping the fn
// after the visit command confirm the stub was called
})
it('works via cy.on event handler', () => {
// need to return the same stub when using cy.visit
// and cy.reload calls that create new "window" objects
// tip: use the cy.on('window:before:load', ...) event listener
// which is called during cy.visit and during cy.reload
// during the test reload the page several times, then check
// the right number of "window.track" calls was made
// https://on.cypress.io/catalog-of-events
})
it('works via Cypress.on event handler', () => {
// create a single stub in the test
// return it to anyone trying to use window.track
// from Cypress.on('window:before:load') callback
// https://on.cypress.io/catalog-of-events
})
})