Skip to content

Commit 2483c63

Browse files
levibuzolicfacebook-github-bot
authored andcommitted
Add missing remove method to addEventListener Jest mocks (#44270)
Summary: While writing some Jest tests, I noticed some instances of the following error: ``` Cannot read properties of undefined (reading 'remove') ``` Looks like there were two cases where the `{remove: () => {}}` return result was missing in the provided Jest mocks: - `AccessibilityInfo.addEventListener` - `Linking.addEventListener` ## Changelog: [GENERAL] [FIXED] - Added missing `remove` methods for `Linking.addEventListener` and `AccessibilityInfo.addEventListener` Jest mocks Pull Request resolved: #44270 Test Plan: N/A Reviewed By: christophpurrer Differential Revision: D58324784 Pulled By: robhogan fbshipit-source-id: f46bd55db2517413f14182ae1bb81068d8d1e9f6
1 parent 61de7da commit 2483c63

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/react-native/jest/setup.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ jest
137137
.mock('../Libraries/Components/AccessibilityInfo/AccessibilityInfo', () => ({
138138
__esModule: true,
139139
default: {
140-
addEventListener: jest.fn(),
140+
addEventListener: jest.fn(() => ({
141+
remove: jest.fn(),
142+
})),
141143
announceForAccessibility: jest.fn(),
142144
isAccessibilityServiceEnabled: jest.fn(),
143145
isBoldTextEnabled: jest.fn(),
@@ -200,7 +202,9 @@ jest
200202
openURL: jest.fn(),
201203
canOpenURL: jest.fn(() => Promise.resolve(true)),
202204
openSettings: jest.fn(),
203-
addEventListener: jest.fn(),
205+
addEventListener: jest.fn(() => ({
206+
remove: jest.fn(),
207+
})),
204208
getInitialURL: jest.fn(() => Promise.resolve()),
205209
sendIntent: jest.fn(),
206210
}))

0 commit comments

Comments
 (0)