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
| import { NgRedux } from 'ng2-redux'; import { CounterActions } from './counter';
class MockRedux extends NgRedux<any> { constructor(private state: any) { super(null); } dispatch = () => undefined; getState = () => this.state; }
describe('counter action creators', () => { let actions: CounterActions; let mockRedux: NgRedux<any>; let mockState: any = {};
beforeEach(() => { mockRedux = new MockRedux(mockState); actions = new CounterActions(mockRedux); });
it('incrementIfOdd should dispatch INCREMENT_COUNTER action if count is odd', () => { const expectedAction = { type: CounterActions.INCREMENT_COUNTER };
mockState.counter = 3; spyOn(mockRedux, 'dispatch'); actions.incrementIfOdd();
expect(mockRedux.dispatch).toHaveBeenCalled(); expect(mockRedux.dispatch).toHaveBeenCalledWith(expectedAction); });
it('incrementIfOdd should not dispatch INCREMENT_COUNTER action if count is even', () => { mockState.counter = 2; spyOn(mockRedux, 'dispatch'); actions.incrementIfOdd();
expect(mockRedux.dispatch).not.toHaveBeenCalled(); }); });
|