-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathtest.js
75 lines (65 loc) · 2.32 KB
/
test.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
64
65
66
67
68
69
70
71
72
73
74
75
var expect = require('expect');
var createReducer = require('./').createReducer;
describe('createReducer', function() {
it('returns the inital state on the first call with no matches', function() {
var reducerMap = {};
var reducer = createReducer('theintialstate', reducerMap);
expect(reducer(undefined, {type: 'YOLO'})).toEqual('theintialstate');
});
it('returns the correct state on the first call with a matche', function() {
var reducerMap = {
YOLO: function() {
return 'theproperstate';
}
};
var reducer = createReducer('theintialstate', reducerMap);
expect(reducer(undefined, {type: 'YOLO'})).toEqual('theproperstate');
});
it('returns the same state if no value matched', function() {
var reducerMap = {};
var reducer = createReducer({someObj: true}, reducerMap);
var state = reducer(undefined, {type: 'YOLO'});
expect(reducer(state, {type: 'YOLO'})).toEqual(state);
});
it('returns a new state if a value matched', function() {
var reducerMap = {
YOLO: function() {
return {someObj: 2};
}
};
var reducer = createReducer({someObj: 1}, reducerMap);
var state = reducer(undefined, {});
expect(reducer(state, {type: 'YOLO'})).toEqual({someObj: 2});
});
it('warns about undefined action type names, but keeps them intact', function() {
var YOLO = undefined;
var reducerMap = {
[YOLO]: function() {
return 'theproperstate';
}
};
var spy = expect.spyOn(console, 'warn')
var reducer = createReducer({}, reducerMap);
spy.restore();
expect(spy).toHaveBeenCalled()
expect(reducer(undefined, {type: 'undefined'})).toEqual('theproperstate');
});
it('does not warn about undefined action type names if not in development mode', function() {
var NODE_ENV = process.env.NODE_ENV;
process.env.NODE_ENV = 'production';
delete require.cache[require.resolve('./')];
// locally scoped version, should be fine
var createReducer = require('./').createReducer;
var YOLO = undefined;
var reducerMap = {
[YOLO]: function() {
return 'theproperstate';
}
};
var spy = expect.spyOn(console, 'warn')
var reducer = createReducer({}, reducerMap);
process.env.NODE_ENV = NODE_ENV;
spy.restore();
expect(spy).toNotHaveBeenCalled()
});
});