forked from cypress-io/cypress-react-unit-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclicker-spec.js
35 lines (31 loc) · 893 Bytes
/
clicker-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
import React from 'react'
import { mount } from 'cypress-react-unit-test'
describe('Clicker', () => {
const Clicker = ({ click }) => (
<div>
<button onClick={click}>Click me</button>
</div>
)
it('calls the click prop twice', () => {
const onClick = cy.stub()
mount(<Clicker click={onClick} />)
cy.get('button')
.click()
.click()
.then(() => {
// works in this case, but not recommended
// because https://on.cypress.io/then does not retry
expect(onClick).to.be.calledTwice
})
})
it('calls the click prop: best practice', () => {
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')
})
})