Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Add unit tests for savedAccounts middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
slaweet committed Nov 9, 2017
1 parent 83d92c8 commit aab4ee4
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/store/middlewares/savedAccounts.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { expect } from 'chai';
import { spy, mock } from 'sinon';

import { accountLoggedOut } from '../../actions/account';
import { successToastDisplayed } from '../../actions/toaster';
import actionTypes from '../../constants/actions';
import middleware from './savedAccounts';

describe('SavedAccounts middleware', () => {
let store;
let next;

beforeEach(() => {
store = mock();
store.dispatch = spy();
store.getState = () => ({});

next = spy();
});

it('should pass the action to next middleware', () => {
const randomAction = {
type: 'SOME_ACTION',
data: { something: true },
};

middleware(store)(next)(randomAction);
expect(next).to.have.been.calledWith(randomAction);
});

it(`should dispatch successToastDisplayed action on ${actionTypes.accountSaved} action`, () => {
const action = {
type: actionTypes.accountSaved,
data: {},
};
middleware(store)(next)(action);
expect(store.dispatch).to.have.been.calledWith(successToastDisplayed({ label: 'Account saved' }));
});

it(`should dispatch successToastDisplayed action on ${actionTypes.accountRemoved} action`, () => {
const action = {
type: actionTypes.accountRemoved,
data: {},
};
middleware(store)(next)(action);
expect(store.dispatch).to.have.been.calledWith(successToastDisplayed({ label: 'Account was successfully forgotten.' }));
});

it(`should dispatch accountLoggedOut action on ${actionTypes.accountSwitched} action`, () => {
const action = {
type: actionTypes.accountSwitched,
data: {
publicKey: '',
network: 0,
},
};
middleware(store)(next)(action);
expect(store.dispatch).to.have.been.calledWith(accountLoggedOut());
});
});

0 comments on commit aab4ee4

Please sign in to comment.