Skip to content

Commit

Permalink
Add missing remove method to addEventListener Jest mocks (#44270)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
levibuzolic authored and facebook-github-bot committed Jun 8, 2024
1 parent 61de7da commit 2483c63
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/react-native/jest/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ jest
.mock('../Libraries/Components/AccessibilityInfo/AccessibilityInfo', () => ({
__esModule: true,
default: {
addEventListener: jest.fn(),
addEventListener: jest.fn(() => ({
remove: jest.fn(),
})),
announceForAccessibility: jest.fn(),
isAccessibilityServiceEnabled: jest.fn(),
isBoldTextEnabled: jest.fn(),
Expand Down Expand Up @@ -200,7 +202,9 @@ jest
openURL: jest.fn(),
canOpenURL: jest.fn(() => Promise.resolve(true)),
openSettings: jest.fn(),
addEventListener: jest.fn(),
addEventListener: jest.fn(() => ({
remove: jest.fn(),
})),
getInitialURL: jest.fn(() => Promise.resolve()),
sendIntent: jest.fn(),
}))
Expand Down

0 comments on commit 2483c63

Please sign in to comment.