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
64 lines (52 loc) · 1.62 KB
/
setup.ts
File metadata and controls
64 lines (52 loc) · 1.62 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
57
58
59
60
61
62
63
64
import { renderHook } from "@testing-library/react-native";
import { useAnimatedRef } from "react-native-reanimated";
import { useExtraContentPadding } from "..";
import { sv } from "../../../../__fixtures__/sv";
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));
let mockForceLegacy = false;
jest.mock("../../../../architecture", () => ({
get IS_FABRIC() {
return !mockForceLegacy;
},
}));
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) {
return renderHook(() => {
const ref = useAnimatedRef<Reanimated.ScrollView>();
useExtraContentPadding({
scrollViewRef: ref,
blankSpace: options.blankSpace ?? sv(0),
...options,
});
});
};
};
beforeEach(() => {
mockForceLegacy = false;
mockScrollTo.mockClear();
});
export const withLegacyArch = (fn: () => void) => {
mockForceLegacy = true;
fn();
};