Skip to content

Commit

Permalink
test(dynostore): add tests
Browse files Browse the repository at this point in the history
improves #43
  • Loading branch information
aneurysmjs committed Oct 12, 2019
1 parent cdfc2a3 commit 57eb087
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/app/store/config/dynoStore/dynostore.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* eslint-disable import/no-named-as-default-member */
import { createStore as createReduxStore } from 'redux';
import dynoStore, { createStore, reloadStore, injectReducers } from './dynoStore';

describe('Dyno Store', () => {
it('should have main methods', () => {
expect(dynoStore).toHaveProperty('createStore');
expect(dynoStore).toHaveProperty('reloadStore');
expect(dynoStore).toHaveProperty('injectReducers');
expect(dynoStore).toHaveProperty('withStoreModule');
});

it('should create and return a Redux store', () => {
const reduxStore = createReduxStore(() => ({}));
const store = createStore();
expect(JSON.stringify(store, null)).toEqual(JSON.stringify(reduxStore, null));
});

it('should trigger store\'s "dispatch" when reloading the store', () => {
const store = createStore();
const mockDispatch = jest.spyOn(store, 'dispatch');
reloadStore();
expect(mockDispatch).toHaveBeenCalledTimes(1);
expect(mockDispatch).toHaveBeenCalledWith({ type: '@@DYNO_STORE/RELOAD' });
});

it('should add reducer and reload the store', () => {
const store = createStore();
const reducer = { INIT_DYNO_STATE: (): {} => ({}) };
const mockDispatch = jest.spyOn(store, 'dispatch');
injectReducers(reducer);
expect(mockDispatch).toHaveBeenCalledTimes(1);
expect(mockDispatch).toHaveBeenCalledWith({ type: '@@DYNO_STORE/RELOAD' });
});
});

0 comments on commit 57eb087

Please sign in to comment.