Skip to content

Commit 0f2715f

Browse files
authored
Fix Jest mock returning undefined in v2.0.0 (#1842)
* Mocking FlashList and exporting RV is no longer necessary since it's already exported by default * Fix async operation warning in LayoutCommitObserver tests
1 parent a102767 commit 0f2715f

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

jestSetup.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
jest.mock("@shopify/flash-list", () => {
2-
const RecyclerView = jest.requireActual("@shopify/flash-list").RecyclerView;
3-
4-
return {
5-
...jest.requireActual("@shopify/flash-list"),
6-
FlashList: RecyclerView,
7-
};
8-
});
9-
101
jest.mock("@shopify/flash-list/dist/recyclerview/utils/measureLayout", () => {
112
const originalModule = jest.requireActual(
123
"@shopify/flash-list/dist/recyclerview/utils/measureLayout"

src/__tests__/LayoutCommitObserver.test.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from "react";
22
import { render } from "@quilted/react-testing";
33

4-
import { RecyclerView } from "../recyclerview/RecyclerView";
54
import { useFlashListContext } from "../recyclerview/RecyclerViewContextProvider";
65
import { LayoutCommitObserver } from "../recyclerview/LayoutCommitObserver";
6+
import { FlashList } from "..";
77

88
describe("LayoutCommitObserver", () => {
99
it("should not alter ref captured by child", () => {
@@ -20,7 +20,7 @@ describe("LayoutCommitObserver", () => {
2020
let commitLayoutEffectCount = 0;
2121

2222
const content = (
23-
<RecyclerView
23+
<FlashList
2424
testID="parent"
2525
data={[1]}
2626
renderItem={() => (
@@ -29,7 +29,7 @@ describe("LayoutCommitObserver", () => {
2929
commitLayoutEffectCount++;
3030
}}
3131
>
32-
<RecyclerView
32+
<FlashList
3333
testID="child"
3434
data={[1]}
3535
renderItem={() => (
@@ -53,8 +53,11 @@ describe("LayoutCommitObserver", () => {
5353
/>
5454
);
5555

56-
render(content);
56+
const renderResult = render(content);
5757

5858
expect(commitLayoutEffectCount).toBe(3);
59+
60+
// Force unmount to trigger cleanup of async operations
61+
renderResult.unmount();
5962
});
6063
});

src/__tests__/RecyclerView.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import "@quilted/react-testing/matchers";
44
import { render } from "@quilted/react-testing";
55

66
import { FlashListRef } from "../FlashListRef";
7-
import { RecyclerView } from "../recyclerview/RecyclerView";
7+
import { FlashList } from "..";
88

99
// Mock measureLayout to return fixed dimensions
1010
jest.mock("../recyclerview/utils/measureLayout", () => {
@@ -49,7 +49,7 @@ const renderRecyclerView = (args: {
4949
data,
5050
} = args;
5151
return render(
52-
<RecyclerView
52+
<FlashList
5353
ref={ref}
5454
data={
5555
data ?? [

0 commit comments

Comments
 (0)