-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhello-world-component-spec.js
51 lines (43 loc) · 1.24 KB
/
hello-world-component-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
/// <reference types="cypress" />
import { HelloWorld, HelloYou } from '../../components/hello-world'
import { mount } from '../../src'
/* eslint-env mocha */
describe('HelloWorld', () => {
// component without any actions or internal state
beforeEach(() => {
const state = {}
const actions = {}
mount(state, actions, HelloWorld)
})
it('shows greeting', () => {
cy.contains('.greeting', 'Hello, World')
})
})
describe('HelloYou', () => {
// component with state and an action
const state = {
name: 'person'
}
beforeEach(() => {
const actions = {
setName: name => state => ({ name })
}
mount(state, actions, HelloYou)
})
it('shows greeting', () => {
cy.contains('.greeting', 'Hello, person')
})
it('changes greeting using action', () => {
// Cypress.main is the mounted value which is
// the app's actions object
cy.log('changing name')
Cypress.main.setName('Great Person!')
cy.contains('.greeting', 'Hello, Great Person!')
})
it('mutates name in the state', () => {
Cypress.main.setName('Great Person!')
// mount function adds utility method to get the
// current state object
Cypress.main._getState().its('name').should('equal', 'Great Person!')
})
})