-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtimer-start-logic.spec.js
82 lines (71 loc) · 2.21 KB
/
timer-start-logic.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
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
76
77
78
79
80
81
82
import expect from 'expect';
import { TIMER_START, TIMER_START_ERROR,
timerStart } from '../src/timer/actions';
import { timerStartLogic } from '../src/timer/logic';
describe('timerStartLogic', () => {
describe('initial state, timerStart.validate', () => {
let allow;
let reject;
let dispatch;
beforeEach((done) => {
const getState = () => ({
timer: {
value: 10,
status: 'stopped'
}
});
const action = timerStart();
allow = expect.createSpy().andCall(() => done());
reject = (action) => done(action); // pass as error to done
timerStartLogic.validate({ getState, action }, allow, reject);
});
it('should have called allow with the action', () => {
expect(allow.calls.length).toBe(1);
expect(allow.calls[0].arguments[0]).toEqual({
type: 'TIMER_START'
});
});
});
describe('10, running, timerStart.validate', () => {
let allow;
let reject;
let dispatch;
beforeEach((done) => {
const getState = () => ({
timer: {
value: 10,
status: 'started'
}
});
const action = timerStart();
allow = (action) => done(action); // pass as error to done
reject = expect.createSpy().andCall(() => done());
timerStartLogic.validate({ getState, action }, allow, reject);
});
it('should have called reject with undefined', () => {
expect(reject.calls.length).toBe(1);
expect(reject.calls[0].arguments[0]).toBe(undefined);
});
});
describe('0, stopped, timerStart.validate', () => {
let allow;
let reject;
let dispatch;
beforeEach((done) => {
const getState = () => ({
timer: {
value: 0,
status: 'stopped'
}
});
const action = timerStart();
allow = (action) => done(action); // pass as error to done
reject = expect.createSpy().andCall(() => done());
timerStartLogic.validate({ getState, action }, allow, reject);
});
it('should have called reject with timerStartError action', () => {
expect(reject.calls.length).toBe(1);
expect(reject.calls[0].arguments[0].type).toBe(TIMER_START_ERROR);
});
});
});