@applicaster/zapp-react-native-utils
Version:
Applicaster Zapp React Native utilities package
43 lines (33 loc) • 1.19 kB
text/typescript
import { renderHook } from "@testing-library/react-hooks";
jest.mock(
"@applicaster/zapp-react-native-ui-components/Contexts/ScreenTrackedViewPositionsContext",
() => ({
useScreenTrackedViewPositionsContext: jest.fn().mockReturnValue({
value: {
"123": { componentId: "123", centerX: 0.4, centerY: 0.5 },
"124": { componentId: "124", centerX: 0.2, centerY: 0.3 },
},
}),
})
);
jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation");
jest.useFakeTimers();
const {
useTrackCurrentAutoScrollingElement,
} = require("../useTrackCurrentAutoScrollingElement");
describe("useTrackCurrentAutoScrollingElement", () => {
it("should return true if component is focused", async () => {
const { result } = renderHook(() =>
useTrackCurrentAutoScrollingElement("123")
);
// Fast-forward until all timers have been executed
jest.advanceTimersByTime(3000);
expect(result.current).toBe(true);
});
it("should return false if component isnot focused", () => {
const { result } = renderHook(() =>
useTrackCurrentAutoScrollingElement("124")
);
expect(result.current).toBe(false);
});
});