forked from bahmutov/cypress-hyperapp-unit-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver-todos-spec.js
68 lines (62 loc) · 1.52 KB
/
server-todos-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
62
63
64
65
66
67
68
/// <reference types="cypress" />
import { h } from 'hyperapp'
import { ServerTodos } from '../../components/server-todos'
import { mount } from '../../src'
import { toggle } from '../../actions'
/* eslint-env mocha */
describe('Server Todos', () => {
const mockTodos = [
{
id: 1,
title: 'Stub server',
completed: false
},
{
id: 2,
title: 'Test app',
completed: false
},
{
id: 3,
title: 'Profit!',
completed: true
}
]
beforeEach(() => {
// expect XHR from the component
// and respond with mock list
cy.server()
cy.route('/todos?_limit=3', mockTodos).as('todos')
})
context('Stubbed server', () => {
beforeEach(() => {
const state = {
todos: []
}
const actions = {
setTodos: todos => state => ({ todos }),
toggle
}
const view = (state, actions) =>
h(ServerTodos, {
n: 3,
todosLoaded: actions.setTodos,
todos: state.todos,
toggle: actions.toggle
})
mount(state, actions, view)
})
it('shows todos', () => {
cy.contains('Todo')
cy.get('.todo').should('have.length', 3)
cy.get('.todo').first().contains('Stub server')
})
it('stubs XHR response', () => {
cy.wait('@todos').its('response.body').should('deep.equal', mockTodos)
})
it('can toggle item', () => {
cy.get('.todo').first().click()
cy.get('.todo').first().find('.toggle').should('be.checked')
})
})
})