-
Notifications
You must be signed in to change notification settings - Fork 0
/
counter-spec.js
50 lines (46 loc) · 974 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// @ts-check
/// <reference types="Cypress" />
import xs from 'xstream'
import { div, button, p } from '@cycle/dom'
import { mount } from '../..'
function main (sources) {
const action$ = xs.merge(
sources.DOM.select('.decrement')
.events('click')
.map(ev => -1),
sources.DOM.select('.increment')
.events('click')
.map(ev => +1)
)
const count$ = action$.fold((acc, x) => acc + x, 0)
const vdom$ = count$.map(count =>
div([
button('.decrement', 'Decrement'),
button('.increment', 'Increment'),
p('Counter: ' + count)
])
)
return {
DOM: vdom$
}
}
/* eslint-env mocha */
describe('Counter', () => {
beforeEach(() => {
mount(main)
})
it('count up and down', () => {
cy
.get('.increment')
.click()
.click()
.click()
.click()
cy.contains('Counter: 4')
cy
.get('.decrement')
.click()
.click()
cy.contains('Counter: 2')
})
})