Skip to content
This repository has been archived by the owner on Feb 3, 2020. It is now read-only.

Commit

Permalink
test: make tests more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
knpwrs committed Feb 5, 2019
1 parent f08e54c commit 3dd6063
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/handle-action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ test('handles specific action', () => {
const re = handleAction<typeof state>(ac1, (draft) => {
draft.counter += 1;
}, state);
expect(re(state, ac1())).toEqual({ counter: 1 });
expect(re(state, ac2())).toEqual({ counter: 0 });
const newState1 = re(state, ac1());
expect(newState1).toEqual({ counter: 1 });
expect(newState1).not.toBe(state);
const newState2 = re(state, ac2());
expect(newState2).toEqual({ counter: 0 });
expect(newState2).toBe(state);
});

test('handles specific action with payload', () => {
Expand All @@ -21,6 +25,10 @@ test('handles specific action with payload', () => {
const re = handleAction<typeof state>(ac1, (draft, { payload }) => {
draft.counter += payload.num;
}, state);
expect(re(state, ac1({ num: 10 }))).toEqual({ counter: 10 });
expect(re(state, ac2({ num: 10 }))).toEqual({ counter: 0 });
const newState1 = re(state, ac1({ num: 10 }));
expect(newState1).toEqual({ counter: 10 });
expect(newState1).not.toBe(state);
const newState2 = re(state, ac2({ num: 10 }));
expect(newState2).toEqual({ counter: 0 });
expect(newState2).toBe(state);
});

0 comments on commit 3dd6063

Please sign in to comment.