Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80529 views
1
'use strict';
2
3
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj['default'] : obj; };
4
5
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; };
6
7
var _import = require('../TestUtils');
8
9
var TestUtils = _interopRequireWildcard(_import);
10
11
var _sinon = require('sinon');
12
13
var sinon = _interopRequire(_sinon);
14
15
describe('TestUtils', function () {
16
describe('#simulateAction', function () {
17
it('calls the stores handler', function () {
18
var store = mockStore();
19
var actionFunc = function actionFunc() {};
20
actionFunc._id = 'actionFunc';
21
22
TestUtils.simulateAction(store, 'foo', 'foo body');
23
TestUtils.simulateAction(store, actionFunc, 'actionFunc body');
24
25
expect(store.handler.calledTwice).to.be['true'];
26
27
expect(store.handler.getCall(0).args[0]).to.deep.equal({
28
actionId: 'foo',
29
body: 'foo body'
30
});
31
32
expect(store.handler.getCall(1).args[0]).to.deep.equal({
33
actionId: 'actionFunc',
34
body: 'actionFunc body'
35
});
36
});
37
});
38
39
describe('#simulateActionAsync', function () {
40
it('it handles async begin', function () {
41
var store = mockStore();
42
43
TestUtils.simulateActionAsync(store, 'foo', 'begin');
44
45
expect(store.handler.calledOnce).to.be['true'];
46
expect(store.handler.firstCall.args[0]).to.deep.equal({
47
actionId: 'foo',
48
async: 'begin'
49
});
50
});
51
52
it('it handles async begin w/ action args', function () {
53
var store = mockStore();
54
55
TestUtils.simulateActionAsync(store, 'foo', 'begin', 'arg1', 'arg2');
56
57
expect(store.handler.calledOnce).to.be['true'];
58
expect(store.handler.firstCall.args[0]).to.deep.equal({
59
actionId: 'foo',
60
async: 'begin',
61
actionArgs: ['arg1', 'arg2']
62
});
63
});
64
65
it('it handles async success', function () {
66
var store = mockStore();
67
68
TestUtils.simulateActionAsync(store, 'foo', 'success', { foo: 'bar' });
69
70
expect(store.handler.calledOnce).to.be['true'];
71
expect(store.handler.firstCall.args[0]).to.deep.equal({
72
actionId: 'foo',
73
async: 'success',
74
body: {
75
foo: 'bar'
76
}
77
});
78
});
79
80
it('it handles async failure', function () {
81
var store = mockStore();
82
83
TestUtils.simulateActionAsync(store, 'foo', 'failure', 'error message');
84
85
expect(store.handler.calledOnce).to.be['true'];
86
expect(store.handler.firstCall.args[0]).to.deep.equal({
87
actionId: 'foo',
88
async: 'failure',
89
error: 'error message'
90
});
91
});
92
93
it('it throws error with invalid asyncAction', function () {
94
var store = mockStore();
95
var simulate = function simulate() {
96
return TestUtils.simulateActionAsync(store, 'foo', 'fizbin');
97
};
98
99
expect(simulate).to['throw']('asyncAction must be one of: begin, success or failure');
100
});
101
});
102
});
103
104
function mockStore() {
105
return {
106
handler: sinon.spy()
107
};
108
}
109