Skip to content

Commit d42decc

Browse files
committed
Add tests for Redux enhancer
1 parent 816fc95 commit d42decc

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

test/app/inject/enhancer.spec.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import 'babel-polyfill';
2+
import expect from 'expect';
3+
import { createStore, compose } from 'redux';
4+
import { listenMessage } from '../../utils/inject';
5+
import '../../../src/browser/extension/inject/pageScript';
6+
7+
function counter(state = 0, action) {
8+
switch (action.type) {
9+
case 'INCREMENT': return state + 1;
10+
case 'DECREMENT': return state - 1;
11+
default: return state;
12+
}
13+
}
14+
15+
describe('Redux enhancer', () => {
16+
it('should create the store', async () => {
17+
const message = await listenMessage(() => {
18+
window.store = createStore(counter, window.devToolsExtension());
19+
expect(window.store).toBeA('object');
20+
});
21+
expect(message.type).toBe('INIT_INSTANCE');
22+
});
23+
24+
it('should perform actions', () => {
25+
expect(window.store.getState()).toBe(0);
26+
window.store.dispatch({ type: 'INCREMENT' });
27+
expect(window.store.getState()).toBe(1);
28+
window.store.dispatch({ type: 'INCREMENT' });
29+
expect(window.store.getState()).toBe(2);
30+
});
31+
32+
it('should create the store with config parameters', async () => {
33+
const name = 'Some title';
34+
const message = await listenMessage(() => {
35+
window.store = createStore(counter, window.devToolsExtension({
36+
name,
37+
actionsBlacklist: ['SOME_ACTION'],
38+
statesFilter: state => state,
39+
serializeState: (key, value) => value
40+
}));
41+
expect(window.store).toBeA('object');
42+
});
43+
expect(message.type).toBe('INIT_INSTANCE');
44+
expect(message.name).toBe(name);
45+
});
46+
47+
it('should create the store using old Redux api', async () => {
48+
const message = await listenMessage(() => {
49+
window.store = window.devToolsExtension()(createStore)(counter);
50+
expect(window.store).toBeA('object');
51+
});
52+
expect(message.type).toBe('INIT_INSTANCE');
53+
});
54+
55+
it('should create the store with several enhancers', async () => {
56+
const testEnhancer = next =>
57+
(reducer, initialState, enhancer) => next(reducer, initialState, enhancer);
58+
const message = await listenMessage(() => {
59+
window.store = createStore(counter, compose(
60+
testEnhancer,
61+
window.devToolsExtension())
62+
);
63+
expect(window.store).toBeA('object');
64+
});
65+
expect(message.type).toBe('INIT_INSTANCE');
66+
});
67+
});

0 commit comments

Comments
 (0)