Skip to content

Commit

Permalink
test(store): add action with default parameter test
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver committed Mar 10, 2021
1 parent f91da7d commit 3979ca2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion modules/store/spec/reducer_creator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ describe('classes/reducer', function (): void {
describe('base', () => {
const bar = createAction('[foobar] BAR', props<{ bar: number }>());
const foo = createAction('[foobar] FOO', props<{ foo: number }>());
const withDefaultParameter = createAction(
'[foobar] withDefaultParameter',
(foo: number = 4, bar: number = 7) => ({
foo,
bar,
})
);

describe('on', () => {
it('should support reducers with multiple actions', () => {
Expand All @@ -32,7 +39,8 @@ describe('classes/reducer', function (): void {
const fooBarReducer = createReducer(
{} as State,
on(foo, (state, { foo }) => ({ ...state, foo })),
on(bar, (state, { bar }) => ({ ...state, bar }))
on(bar, (state, { bar }) => ({ ...state, bar })),
on(withDefaultParameter, (_state, { type: _, ...payload }) => payload)
);

expect(typeof fooBarReducer).toEqual('function');
Expand All @@ -45,6 +53,9 @@ describe('classes/reducer', function (): void {

state = fooBarReducer(state, bar({ bar: 54 }));
expect(state).toEqual({ foo: 42, bar: 54 });

state = fooBarReducer(state, withDefaultParameter());
expect(state).toEqual({ foo: 4, bar: 7 });
});

it('should create a primitive reducer', () => {
Expand Down

0 comments on commit 3979ca2

Please sign in to comment.