forked from cypress-io/cypress-react-unit-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcard-without-effect-spec.js
61 lines (52 loc) · 1.42 KB
/
card-without-effect-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
/// <reference types="cypress" />
import Card from './card-without-effect.jsx'
import React from 'react'
import { mount, unmount } from 'cypress-react-unit-test'
import { unmountComponentAtNode } from 'react-dom'
it('should select null after timing out', () => {
const onSelect = cy.stub()
// https://on.cypress.io/clock
cy.clock()
mount(<Card onSelect={onSelect} />)
cy.tick(100).then(() => {
expect(onSelect).to.not.have.been.called
})
cy.tick(5000).then(() => {
expect(onSelect).to.have.been.calledWith(null)
})
})
it('should cleanup on being removed', () => {
const onSelect = cy.stub()
cy.clock()
mount(<Card onSelect={onSelect} />)
cy.tick(100).then(() => {
expect(onSelect).to.not.have.been.called
})
cy.get('#cypress-root').then($el => {
unmountComponentAtNode($el[0])
})
cy.tick(5000).then(() => {
expect(onSelect).to.not.have.been.called
})
})
it('should cleanup on being removed (using unmount)', () => {
const onSelect = cy.stub()
cy.clock()
mount(<Card onSelect={onSelect} />)
cy.tick(100).then(() => {
expect(onSelect).to.not.have.been.called
})
unmount()
cy.tick(5000).then(() => {
expect(onSelect).to.not.have.been.called
})
})
it('should accept selections', () => {
const onSelect = cy.stub()
mount(<Card onSelect={onSelect} />)
cy.get("[data-testid='2']")
.click()
.then(() => {
expect(onSelect).to.have.been.calledWith(2)
})
})