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

Commit 3dd6063

Browse files
committed
test: make tests more robust
1 parent f08e54c commit 3dd6063

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/handle-action.test.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ test('handles specific action', () => {
1010
const re = handleAction<typeof state>(ac1, (draft) => {
1111
draft.counter += 1;
1212
}, state);
13-
expect(re(state, ac1())).toEqual({ counter: 1 });
14-
expect(re(state, ac2())).toEqual({ counter: 0 });
13+
const newState1 = re(state, ac1());
14+
expect(newState1).toEqual({ counter: 1 });
15+
expect(newState1).not.toBe(state);
16+
const newState2 = re(state, ac2());
17+
expect(newState2).toEqual({ counter: 0 });
18+
expect(newState2).toBe(state);
1519
});
1620

1721
test('handles specific action with payload', () => {
@@ -21,6 +25,10 @@ test('handles specific action with payload', () => {
2125
const re = handleAction<typeof state>(ac1, (draft, { payload }) => {
2226
draft.counter += payload.num;
2327
}, state);
24-
expect(re(state, ac1({ num: 10 }))).toEqual({ counter: 10 });
25-
expect(re(state, ac2({ num: 10 }))).toEqual({ counter: 0 });
28+
const newState1 = re(state, ac1({ num: 10 }));
29+
expect(newState1).toEqual({ counter: 10 });
30+
expect(newState1).not.toBe(state);
31+
const newState2 = re(state, ac2({ num: 10 }));
32+
expect(newState2).toEqual({ counter: 0 });
33+
expect(newState2).toBe(state);
2634
});

0 commit comments

Comments
 (0)