Skip to content

Commit 9c714c0

Browse files
committed
self code review
1 parent d97cab0 commit 9c714c0

File tree

5 files changed

+9
-44
lines changed

5 files changed

+9
-44
lines changed

src/__tests__/fire-event-async.test.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -644,16 +644,14 @@ describe('React.Suspense integration', () => {
644644

645645
test('should handle unmounted elements gracefully in async mode', async () => {
646646
const onPress = jest.fn();
647-
const result = render(
647+
render(
648648
<TouchableOpacity onPress={onPress}>
649649
<Text>Test</Text>
650650
</TouchableOpacity>,
651651
);
652652

653653
const element = screen.getByText('Test');
654-
655-
// Unmount the component
656-
result.unmount();
654+
screen.unmount();
657655

658656
// Firing async event on unmounted element should not crash
659657
await fireEventAsync.press(element);

src/__tests__/fire-event.test.tsx

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -556,44 +556,16 @@ describe('native events', () => {
556556

557557
test('should handle unmounted elements gracefully', () => {
558558
const onPress = jest.fn();
559-
const result = render(
559+
render(
560560
<TouchableOpacity onPress={onPress}>
561561
<Text>Test</Text>
562562
</TouchableOpacity>,
563563
);
564564

565565
const element = screen.getByText('Test');
566-
567-
// Unmount the component
568-
result.unmount();
566+
screen.unmount();
569567

570568
// Firing event on unmounted element should not crash
571569
fireEvent.press(element);
572570
expect(onPress).not.toHaveBeenCalled();
573571
});
574-
575-
test('should handle invalid scroll event data gracefully', () => {
576-
const onScrollSpy = jest.fn();
577-
render(<ScrollView testID="scroll-view" onScroll={onScrollSpy} />);
578-
579-
const scrollView = screen.getByTestId('scroll-view');
580-
581-
// Test with malformed event data that would cause an error in tryGetContentOffset
582-
fireEvent.scroll(scrollView, { malformed: 'data' });
583-
expect(onScrollSpy).toHaveBeenCalled();
584-
});
585-
586-
test('should handle scroll event with invalid contentOffset', () => {
587-
const onScrollSpy = jest.fn();
588-
render(<ScrollView testID="scroll-view" onScroll={onScrollSpy} />);
589-
590-
const scrollView = screen.getByTestId('scroll-view');
591-
592-
// Test with event data that has invalid contentOffset structure
593-
fireEvent.scroll(scrollView, {
594-
nativeEvent: {
595-
contentOffset: { x: 'invalid', y: null },
596-
},
597-
});
598-
expect(onScrollSpy).toHaveBeenCalled();
599-
});

src/__tests__/render-async.test.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ test('renderAsync supports concurrent rendering option', async () => {
5959
expect(screen.root).toBeOnTheScreen();
6060
});
6161

62-
test('renderAsync supports legacy rendering option', async () => {
63-
await renderAsync(<View testID="test" />, { concurrentRoot: false });
64-
expect(screen.root).toBeOnTheScreen();
65-
});
66-
6762
test('rerender function throws error when used with renderAsync', async () => {
6863
await renderAsync(<Banana />);
6964

src/__tests__/render.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,20 +244,20 @@ test('supports concurrent rendering', () => {
244244
expect(screen.root).toBeOnTheScreen();
245245
});
246246

247-
test('updateAsync updates the component asynchronously', async () => {
247+
test('rerenderAsync updates the component asynchronously', async () => {
248248
const fn = jest.fn();
249249
const result = render(<Banana onUpdate={fn} />);
250250

251-
await result.updateAsync(<Banana onUpdate={fn} />);
251+
await result.rerenderAsync(<Banana onUpdate={fn} />);
252252

253253
expect(fn).toHaveBeenCalledTimes(1);
254254
});
255255

256-
test('rerenderAsync is an alias for updateAsync', async () => {
256+
test('updateAsync is an alias for rerenderAsync', async () => {
257257
const fn = jest.fn();
258258
const result = render(<Banana onUpdate={fn} />);
259259

260-
await result.rerenderAsync(<Banana onUpdate={fn} />);
260+
await result.updateAsync(<Banana onUpdate={fn} />);
261261

262262
expect(fn).toHaveBeenCalledTimes(1);
263263
});

website/docs/13.x/docs/api/screen.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Async version of `unmount` designed for working with React 19 and React Suspense
100100

101101
:::note
102102

103-
Usually you should not need to call `unmount` as it is done automatically if your test runner supports `afterEach` hook (like Jest, mocha, Jasmine).
103+
Usually you should not need to call `unmountAsync` as it is done automatically if your test runner supports `afterEach` hook (like Jest, mocha, Jasmine).
104104

105105
:::
106106

0 commit comments

Comments
 (0)