forked from bahmutov/todomvc-redux-kuker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixture-spec.js
61 lines (51 loc) · 1.78 KB
/
fixture-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" />
// uses expected values loaded from fixture files
// make sure we are only spying on Kuker Redux events (except for init)
const isKukerRedux = what =>
Cypress._.isPlainObject(what) && what.kuker && what.type !== 'NEW_EMITTER'
// only pick properties we want for testing
const reduxEvent = event => Cypress._.pick(event, 'action', 'state')
describe('Expected fixtures', () => {
beforeEach(() => {
// load two fixtures
cy.fixture('first-event').as('first')
cy.fixture('second-event').as('second')
cy.visit('/', {
onBeforeLoad (win) {
let kuker = cy.spy().as('kuker')
const postMessage = win.postMessage.bind(win)
win.postMessage = (what, target) => {
if (isKukerRedux(what)) {
const sanitized = reduxEvent(what)
kuker(sanitized)
// log better message ourselves
Cypress.log({
name: 'Redux',
message: `${what.action.type} "${what.action.text}"`,
consoleProps () {
return sanitized
}
}).end()
} // else ignore messages
return postMessage(what, target)
}
}
})
})
// notice "function" form of callback
// this is because we need to use "this.first" property
it('adds 2 todos', function () {
cy.get('.new-todo').type('learn testing{enter}')
// confirm the first Redux event
cy.get('@kuker')
.its('lastCall.args.0')
// use loaded fixture "first"
.should('deep.equal', this.first)
cy.get('.new-todo').type('be cool{enter}')
// confirm the second Redux event
cy.get('@kuker')
.its('lastCall.args.0')
.should('deep.equal', this.second)
cy.get('.todo-list li').should('have.length', 2)
})
})