@@ -74,11 +74,11 @@ <h1>Spies, Stubs & Clocks</h1>
7474 < div class ="col-xs-12 ">
7575 < h4 > < a href ="https://on.cypress.io/spy "> cy.spy()</ a > </ h4 >
7676 < 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 = {
7878 foo () {},
7979}
8080
81- let spy = cy.spy(obj, 'foo').as('anyArgs')
81+ const spy = cy.spy(obj, 'foo').as('anyArgs')
8282
8383obj.foo()
8484
@@ -87,14 +87,36 @@ <h4><a href="https://on.cypress.io/spy">cy.spy()</a></h4>
8787
8888 < div class ="col-xs-12 "> < hr > </ div >
8989
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+
90112 < div class ="col-xs-12 ">
91113 < h4 > < a href ="https://on.cypress.io/stub "> cy.stub()</ a > </ h4 >
92114 < 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 >
93115 < pre > < code class ="javascript "> let obj = {
94116 foo () {},
95117}
96118
97- let stub = cy.stub(obj, 'foo').as('foo')
119+ const stub = cy.stub(obj, 'foo').as('foo')
98120
99121obj.foo('foo', 'bar')
100122
@@ -108,7 +130,7 @@ <h4><a href="https://on.cypress.io/clock">cy.clock()</a></h4>
108130 < p > To control time in the browser, use the < a href ="https://on.cypress.io/clock "> < code > cy.clock()</ code > </ a > command.</ p >
109131 < pre > < code class ="javascript "> // create the date in UTC so its always the same
110132// 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()
112134
113135cy.clock(now)
114136cy.visit('http://localhost:8080/commands/spies-stubs-clocks')
@@ -130,7 +152,7 @@ <h4><a href="https://on.cypress.io/tick">cy.tick()</a></h4>
130152 < p > To move time in the browser, use the < a href ="https://on.cypress.io/tick "> < code > cy.tick()</ code > </ a > command.</ p >
131153 < pre > < code class ="javascript "> // create the date in UTC so its always the same
132154// 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()
134156
135157cy.clock(now)
136158cy.visit('http://localhost:8080/commands/spies-stubs-clocks')
0 commit comments