Skip to content

Commit

Permalink
Add mock removeEventListener and currentState method for AppState (#3…
Browse files Browse the repository at this point in the history
…9578)

Summary:
Add mock removeEventListener and currentState method for AppState

When testing the React Native page by Jest, the error TypeError: import_react_native.AppState.removeEventListener is not a function will be reported.

## Changelog:

[General] [ Changed ] - Add mock removeEventListener and currentState method for ```AppState```

Pull Request resolved: #39578

Test Plan:
Print AppState module output
```
AppState: {
      addEventListener: [Function: mockConstructor] {
        _isMockFunction: true,
        getMockImplementation: [Function (anonymous)],
        mock: [Getter/Setter],
        mockClear: [Function (anonymous)],
        mockReset: [Function (anonymous)],
        mockRestore: [Function (anonymous)],
        mockReturnValueOnce: [Function (anonymous)],
        mockResolvedValueOnce: [Function (anonymous)],
        mockRejectedValueOnce: [Function (anonymous)],
        mockReturnValue: [Function (anonymous)],
        mockResolvedValue: [Function (anonymous)],
        mockRejectedValue: [Function (anonymous)],
        mockImplementationOnce: [Function (anonymous)],
        mockImplementation: [Function (anonymous)],
        mockReturnThis: [Function (anonymous)],
        mockName: [Function (anonymous)],
        getMockName: [Function (anonymous)]
      },
      removeEventListener: [Function: mockConstructor] {
        _isMockFunction: true,
        getMockImplementation: [Function (anonymous)],
        mock: [Getter/Setter],
        mockClear: [Function (anonymous)],
        mockReset: [Function (anonymous)],
        mockRestore: [Function (anonymous)],
        mockReturnValueOnce: [Function (anonymous)],
        mockResolvedValueOnce: [Function (anonymous)],
        mockRejectedValueOnce: [Function (anonymous)],
        mockReturnValue: [Function (anonymous)],
        mockResolvedValue: [Function (anonymous)],
        mockRejectedValue: [Function (anonymous)],
        mockImplementationOnce: [Function (anonymous)],
        mockImplementation: [Function (anonymous)],
        mockReturnThis: [Function (anonymous)],
        mockName: [Function (anonymous)],
        getMockName: [Function (anonymous)]
      },
      currentState: [Function: mockConstructor] {
        _isMockFunction: true,
        getMockImplementation: [Function (anonymous)],
        mock: [Getter/Setter],
        mockClear: [Function (anonymous)],
        mockReset: [Function (anonymous)],
        mockRestore: [Function (anonymous)],
        mockReturnValueOnce: [Function (anonymous)],
        mockResolvedValueOnce: [Function (anonymous)],
        mockRejectedValueOnce: [Function (anonymous)],
        mockReturnValue: [Function (anonymous)],
        mockResolvedValue: [Function (anonymous)],
        mockRejectedValue: [Function (anonymous)],
        mockImplementationOnce: [Function (anonymous)],
        mockImplementation: [Function (anonymous)],
        mockReturnThis: [Function (anonymous)],
        mockName: [Function (anonymous)],
        getMockName: [Function (anonymous)]
      }
    }
```

Reviewed By: yungsters

Differential Revision: D49504249

Pulled By: robhogan

fbshipit-source-id: c0528ca9da4711f4c39bd2db29bcd34e77c6d4d2
  • Loading branch information
w3cay authored and facebook-github-bot committed Sep 21, 2023
1 parent 42d090c commit 1bda78f
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/react-native/jest/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ jest
addEventListener: jest.fn(() => ({
remove: jest.fn(),
})),
removeEventListener: jest.fn(),
currentState: jest.fn(),
}))
.mock('../Libraries/Linking/Linking', () => ({
openURL: jest.fn(),
Expand Down

0 comments on commit 1bda78f

Please sign in to comment.