forked from cypress-io/cypress-react-unit-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcounter-spec.js
34 lines (31 loc) · 884 Bytes
/
counter-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
/// <reference types="cypress" />
import React from 'react'
import { mount } from 'cypress-react-unit-test'
import { Counter } from './counter.jsx'
/* eslint-env mocha */
describe('Counter with access', () => {
it('works', () => {
mount(<Counter />)
cy.contains('count: 0')
.click()
.contains('count: 1')
.click()
.contains('count: 2')
})
it('allows access via reference', () => {
mount(<Counter />)
// the window.counter was set from the Counter's constructor
cy.window()
.should('have.property', 'counter')
.its('state')
.should('deep.equal', { count: 0 })
// let's change the state of the component
cy.window()
.its('counter')
.invoke('setState', {
count: 101,
})
// the UI should update to reflect the new count
cy.contains('count: 101').should('be.visible')
})
})