forked from JoshuaKGoldberg/mock-react-redux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThunks.test.tsx
59 lines (44 loc) · 1.35 KB
/
Thunks.test.tsx
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
47
48
49
50
51
52
53
54
55
56
57
58
59
/* eslint-disable @typescript-eslint/no-unused-vars */
import { mockReactRedux } from "mock-react-redux";
import { memoize } from "lodash";
import { DispatchProp } from "react-redux";
type Thunk = (dispatch: DispatchProp, getState: () => unknown) => void;
describe("thunks", () => {
test("same function", () => {
const makeCallThunk: Thunk = (_dispatch, _getState) => {
/* ... */
};
const makeCall = () => makeCallThunk;
const { dispatch } = mockReactRedux();
dispatch(makeCall());
expect(dispatch).toHaveBeenCalledWith(makeCallThunk);
});
test("memoized function", () => {
const makeCallWith = memoize(
(_value): Thunk => {
return (_dispatch, _getState) => {
/* ... */
};
},
);
const { dispatch } = mockReactRedux();
const value = {
/* ... */
};
dispatch(makeCallWith(value));
expect(dispatch).toHaveBeenCalledWith(makeCallWith(value));
});
test("memoized function with string-based cache", () => {
const makeCallWith = memoize(
(_value): Thunk => {
return (_dispatch, _getState) => {
/* ... */
};
},
(value) => JSON.stringify(value),
);
const { dispatch } = mockReactRedux();
dispatch(makeCallWith({ value: 0 }));
expect(dispatch).toHaveBeenCalledWith(makeCallWith({ value: 0 }));
});
});