@@ -74,11 +74,11 @@ <h1>Spies, Stubs & Clocks</h1>
74
74
< div class ="col-xs-12 ">
75
75
< h4 > < a href ="https://on.cypress.io/spy "> cy.spy()</ a > </ h4 >
76
76
< p > To wrap a method in a spy, use the < a href ="https://on.cypress.io/spy "> < code > cy.spy()</ code > </ a > command.</ p >
77
- < pre > < code class ="javascript "> let obj = {
77
+ < pre > < code class ="javascript "> const obj = {
78
78
foo () {},
79
79
}
80
80
81
- let spy = cy.spy(obj, 'foo').as('anyArgs')
81
+ const spy = cy.spy(obj, 'foo').as('anyArgs')
82
82
83
83
obj.foo()
84
84
@@ -87,14 +87,36 @@ <h4><a href="https://on.cypress.io/spy">cy.spy()</a></h4>
87
87
88
88
< div class ="col-xs-12 "> < hr > </ div >
89
89
90
+ < div class ="col-xs-12 ">
91
+ < p > < a href ="https://on.cypress.io/spy "> < code > cy.spy()</ code > </ a > retries until the
92
+ assertions that follow it pass.</ p >
93
+ < pre > < code class ="javascript "> const obj = {
94
+ foo () {},
95
+ }
96
+
97
+ cy.spy(obj, 'foo').as('foo')
98
+
99
+ setTimeout(() => {
100
+ obj.foo()
101
+ }, 500)
102
+
103
+ setTimeout(() => {
104
+ obj.foo()
105
+ }, 2500)
106
+
107
+ cy.get('@foo').should('have.been.calledTwice')</ code > </ pre >
108
+ </ div >
109
+
110
+ < div class ="col-xs-12 "> < hr > </ div >
111
+
90
112
< div class ="col-xs-12 ">
91
113
< h4 > < a href ="https://on.cypress.io/stub "> cy.stub()</ a > </ h4 >
92
114
< p > To create a stub and/or replace a function with a stub, use the < a href ="https://on.cypress.io/stub "> < code > cy.stub()</ code > </ a > command.</ p >
93
115
< pre > < code class ="javascript "> let obj = {
94
116
foo () {},
95
117
}
96
118
97
- let stub = cy.stub(obj, 'foo').as('foo')
119
+ const stub = cy.stub(obj, 'foo').as('foo')
98
120
99
121
obj.foo('foo', 'bar')
100
122
@@ -108,7 +130,7 @@ <h4><a href="https://on.cypress.io/clock">cy.clock()</a></h4>
108
130
< p > To control time in the browser, use the < a href ="https://on.cypress.io/clock "> < code > cy.clock()</ code > </ a > command.</ p >
109
131
< pre > < code class ="javascript "> // create the date in UTC so its always the same
110
132
// no matter what local timezone the browser is running in
111
- let now = new Date(Date.UTC(2017, 2, 14)).getTime()
133
+ const now = new Date(Date.UTC(2017, 2, 14)).getTime()
112
134
113
135
cy.clock(now)
114
136
cy.visit('http://localhost:8080/commands/spies-stubs-clocks')
@@ -130,7 +152,7 @@ <h4><a href="https://on.cypress.io/tick">cy.tick()</a></h4>
130
152
< p > To move time in the browser, use the < a href ="https://on.cypress.io/tick "> < code > cy.tick()</ code > </ a > command.</ p >
131
153
< pre > < code class ="javascript "> // create the date in UTC so its always the same
132
154
// no matter what local timezone the browser is running in
133
- let now = new Date(Date.UTC(2017, 2, 14)).getTime()
155
+ const now = new Date(Date.UTC(2017, 2, 14)).getTime()
134
156
135
157
cy.clock(now)
136
158
cy.visit('http://localhost:8080/commands/spies-stubs-clocks')
0 commit comments