forked from cypress-io/cypress-react-unit-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclicker-with-delay-spec.js
49 lines (44 loc) · 1.27 KB
/
clicker-with-delay-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
import React from 'react'
import { mount } from 'cypress-react-unit-test'
describe('Clicker with delay', () => {
const Clicker = ({ click }) => (
<div>
<button onClick={() => setTimeout(click, 500)}>Click me</button>
</div>
)
// Skipped because .then does not retry
// and will fail as soon as "expect" throws an error
it.skip('calls the click prop: then', () => {
const onClick = cy.stub()
mount(<Clicker click={onClick} />)
cy.get('button')
.click()
.click()
.then(() => {
expect(onClick).to.be.calledTwice
})
})
it('calls the click prop: should', () => {
const onClick = cy.stub()
mount(<Clicker click={onClick} />)
cy.get('button')
.click()
.click()
// test works because .should retries the assertion
// and in this case it will not click multiple times
// but just retry the assertion
.should(() => {
expect(onClick).to.be.calledTwice
})
})
it('calls the click prop', () => {
const onClick = cy.stub().as('clicker')
mount(<Clicker click={onClick} />)
cy.get('button')
.click()
.click()
// good practice 💡
// auto-retry the stub until it was called twice
cy.get('@clicker').should('have.been.calledTwice')
})
})