Skip to content

Commit

Permalink
Change tests from redux according to our example
Browse files Browse the repository at this point in the history
  • Loading branch information
zalmoxisus committed Oct 14, 2015
1 parent 65c52ca commit ad53d01
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions test/app/actions/counter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,31 @@ function mockStore(getState, expectedActions, onLastAction) {

describe('actions', () => {
it('increment should create increment action', () => {
expect(actions.increment()).toEqual({ type: actions.INCREMENT_COUNTER });
expect(actions.increment()).toEqual({ type: INCREMENT_COUNTER });
});

it('decrement should create decrement action', () => {
expect(actions.decrement()).toEqual({ type: actions.DECREMENT_COUNTER });
expect(actions.decrement()).toEqual({ type: DECREMENT_COUNTER });
});

it('incrementIfOdd should create increment action', (done) => {
const expectedActions = [
{ type: actions.INCREMENT_COUNTER }
{ type: INCREMENT_COUNTER }
];
const store = mockStore({ counter: 1 }, expectedActions, done);
const store = mockStore({ counter: { count: 1 } }, expectedActions, done);
store.dispatch(actions.incrementIfOdd());
});

it('incrementIfOdd shouldnt create increment action if counter is even', (done) => {
const expectedActions = [];
const store = mockStore({ counter: 2 }, expectedActions);
const store = mockStore({ counter: { count: 2 } }, expectedActions);
store.dispatch(actions.incrementIfOdd());
done();
});

it('incrementAsync should create increment action', (done) => {
const expectedActions = [
{ type: actions.INCREMENT_COUNTER }
{ type: INCREMENT_COUNTER }
];
const store = mockStore({ counter: 0 }, expectedActions, done);
store.dispatch(actions.incrementAsync(100));
Expand Down
10 changes: 5 additions & 5 deletions test/app/reducers/counter.spec.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import expect from 'expect';
import counter from '../../../src/app/reducers/counter';
import { INCREMENT_COUNTER, DECREMENT_COUNTER } from '../../../src/app/actions/counter';
import { INCREMENT_COUNTER, DECREMENT_COUNTER } from '../../../src/app/constants/ActionTypes';

describe('reducers', () => {
describe('counter', () => {
it('should handle initial state', () => {
expect(counter(undefined, {})).toBe(0);
expect(counter(undefined, {})).toEqual({ count: 0 });
});

it('should handle INCREMENT_COUNTER', () => {
expect(counter(1, { type: INCREMENT_COUNTER })).toBe(2);
expect(counter({count: 1}, { type: INCREMENT_COUNTER })).toEqual({ count: 2 });
});

it('should handle DECREMENT_COUNTER', () => {
expect(counter(1, { type: DECREMENT_COUNTER })).toBe(0);
expect(counter({count: 1}, { type: DECREMENT_COUNTER })).toEqual({ count: 0 });
});

it('should handle unknown action type', () => {
expect(counter(1, { type: 'unknown' })).toBe(1);
expect(counter({count: 1}, { type: 'unknown' })).toEqual({ count: 1 });
});
});
});

0 comments on commit ad53d01

Please sign in to comment.