forked from cypress-io/cypress-react-unit-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmouse-spec.js
38 lines (36 loc) · 1.07 KB
/
mouse-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
/// <reference types="cypress" />
import React from 'react'
import { mount, unmount } from 'cypress-react-unit-test'
import MouseMovement from './mouse-movement'
describe('Renderless component', () => {
it('works', () => {
// let's also spy on "console.log" calls
// to make sure the entire sequence of calls happens
cy.window()
.its('console')
.then(console => {
cy.spy(console, 'log').as('log')
})
const onMoved = cy.stub()
mount(<MouseMovement onMoved={onMoved} />)
cy.get('#cypress-root').should('be.empty')
cy.document()
.trigger('mousemove')
.then(() => {
expect(onMoved).to.have.been.calledWith(true)
unmount()
})
cy.get('@log')
.its('callCount')
.should('equal', 4)
cy.get('@log')
.invoke('getCalls')
.then(calls => calls.map(call => call.args[0]))
.should('deep.equal', [
'MouseMovement constructor',
'MouseMovement componentWillMount',
'MouseMovement onMouseMove',
'MouseMovement componentWillUnmount',
])
})
})