Skip to content

Commit 4bf8ae5

Browse files
committed
Fix useExtraContentPadding tests by removing jest.resetModules and dynamic require
jest.resetModules() was causing React to be reloaded, creating multiple React instances and violating the Rules of Hooks. The tests used top-level jest.mock() which doesn't require module resetting between tests - the mock is already applied globally. The dynamic require pattern was cargo-culted from useChatKeyboard tests which use jest.doMock() and legitimately need jest.resetModules(), but it served no purpose here and was actively harmful.
1 parent b696c63 commit 4bf8ae5

1 file changed

Lines changed: 2 additions & 8 deletions

File tree

  • src/components/KeyboardChatScrollView/useExtraContentPadding/__fixtures__

src/components/KeyboardChatScrollView/useExtraContentPadding/__fixtures__/setup.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { renderHook } from "@testing-library/react-native";
22
import { useAnimatedRef } from "react-native-reanimated";
33

44
import { sv } from "../../../../__fixtures__/sv";
5+
import { useExtraContentPadding } from "..";
56

6-
import type { useExtraContentPadding } from "..";
77
import type { SharedValue } from "react-native-reanimated";
88
import type Reanimated from "react-native-reanimated";
99

@@ -33,15 +33,10 @@ type RenderOptions = Omit<
3333

3434
export const createRender = () => {
3535
return function render(options: RenderOptions) {
36-
// eslint-disable-next-line @typescript-eslint/no-var-requires
37-
const mod = require("..") as {
38-
useExtraContentPadding: typeof useExtraContentPadding;
39-
};
40-
4136
return renderHook(() => {
4237
const ref = useAnimatedRef<Reanimated.ScrollView>();
4338

44-
mod.useExtraContentPadding({
39+
useExtraContentPadding({
4540
scrollViewRef: ref,
4641
blankSpace: options.blankSpace ?? sv(0),
4742
...options,
@@ -51,6 +46,5 @@ export const createRender = () => {
5146
};
5247

5348
beforeEach(() => {
54-
jest.resetModules();
5549
mockScrollTo.mockClear();
5650
});

0 commit comments

Comments
 (0)