forked from kirillzyusko/react-native-keyboard-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ts
More file actions
56 lines (46 loc) · 1.57 KB
/
setup.ts
File metadata and controls
56 lines (46 loc) · 1.57 KB
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
import { renderHook } from "@testing-library/react-native";
import { useAnimatedRef } from "react-native-reanimated";
import { sv } from "../../../../__fixtures__/sv";
import type { useExtraContentPadding } from "..";
import type { SharedValue } from "react-native-reanimated";
import type Reanimated from "react-native-reanimated";
export const mockScrollTo = jest.fn();
export let reactionEffect: (current: number, previous: number | null) => void;
export const flushRAF = () => new Promise((resolve) => setTimeout(resolve, 0));
jest.mock("react-native-reanimated", () => ({
...require("react-native-reanimated/mock"),
scrollTo: (...args: unknown[]) => mockScrollTo(...args),
useAnimatedReaction: (
producer: () => number,
effect: (current: number, previous: number | null) => void,
) => {
producer();
reactionEffect = effect;
},
}));
type RenderOptions = Omit<
Parameters<typeof useExtraContentPadding>[0],
"scrollViewRef" | "blankSpace"
> & {
blankSpace?: SharedValue<number>;
};
export const createRender = () => {
return function render(options: RenderOptions) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const mod = require("..") as {
useExtraContentPadding: typeof useExtraContentPadding;
};
return renderHook(() => {
const ref = useAnimatedRef<Reanimated.ScrollView>();
mod.useExtraContentPadding({
scrollViewRef: ref,
blankSpace: options.blankSpace ?? sv(0),
...options,
});
});
};
};
beforeEach(() => {
jest.resetModules();
mockScrollTo.mockClear();
});