-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
56 lines (45 loc) · 1.47 KB
/
index.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
import chai, { expect } from 'chai'
import sinon from 'sinon'
import sinonChai from 'sinon-chai'
chai.use(sinonChai);
import { createStore, applyMiddleware } from 'redux'
import createSagaMiddleware from 'redux-saga'
import * as effects from 'redux-saga/effects'
import 'babel-polyfill'
import createCombineLatest from '../src/index.js'
const spy = sinon.spy()
function* handleActions(actions) {
spy(actions)
}
const combineLatest = createCombineLatest(effects)
function* saga() {
yield combineLatest(['type1', 'type2'], handleActions)
}
const sagaMiddleware = createSagaMiddleware(saga)
const store = createStore(
(state) => state,
applyMiddleware(sagaMiddleware)
)
describe('combineLatest', () => {
const action1 = { type: 'type1', some: 'payload' }
const action2 = { type: 'type2', some: 'payload' }
const action3 = { type: 'type2', other: 'payload' }
describe('when only one action type has been dispatched', () => {
it('should not yield saga yet', () => {
store.dispatch(action1)
expect(spy).not.to.be.called
})
})
describe('when all action types have been dispatched', () => {
it('should yield saga with all actions', () => {
store.dispatch(action2)
expect(spy).to.be.calledWith([action1, action2])
})
})
describe('when a third action is dispatched', () => {
it('should yield saga with latest actions of each type', () => {
store.dispatch(action3)
expect(spy).to.be.calledWith([action1, action3])
})
})
})