-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
63 lines (61 loc) · 2 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
57
58
59
60
61
62
63
'use strict'
var saga = require('redux-saga')
var effects = require('redux-saga/effects')
module.exports = function fromGenerator (t, generator) {
var _next = function () {
var args = Array.prototype.slice.call(arguments)
return generator.next.apply(generator, args)
}
var _throw = function () {
var args = Array.prototype.slice.call(arguments)
return generator.throw.apply(generator, args)
}
var _nextIs = function (fn, mock, effect) {
return function () {
var args = Array.prototype.slice.call(arguments)
return t.deepEqual(fn(mock).value, effect.apply(null, args))
}
}
var _returns = function (fn, mock) {
return function (value) {
return t.deepEqual(fn(mock), {done: true, value: value})
}
}
function wrap (fn) {
return function (mock) {
return {
take: _nextIs(fn, mock, effects.take),
put: _nextIs(fn, mock, effects.put),
call: _nextIs(fn, mock, effects.call),
cps: _nextIs(fn, mock, effects.cps),
fork: _nextIs(fn, mock, effects.fork),
spawn: _nextIs(fn, mock, effects.spawn),
join: _nextIs(fn, mock, effects.join),
cancel: _nextIs(fn, mock, effects.cancel),
select: _nextIs(fn, mock, effects.select),
actionChannel: _nextIs(fn, mock, effects.actionChannel),
cancelled: _nextIs(fn, mock, effects.cancelled),
returns: _returns(fn, mock)
}
}
}
return {
callNext: _next,
nextIs: function (effect) {
return t.deepEqual(_next().value, effect)
},
throwNext: wrap(_throw),
next: wrap(_next),
takeEvery: function () {
var args = Array.prototype.slice.call(arguments)
return t.deepEqual(_next().value, saga.takeEvery.apply(null, args).next().value)
},
takeLatest: function () {
var args = Array.prototype.slice.call(arguments)
return t.deepEqual(_next().value, saga.takeLatest.apply(null, args).next().value)
},
done: function (value) {
return this.next().returns(value)
}
}
}