Skip to content

Commit 59c7b2c

Browse files
MoOxfacebook-github-bot
authored andcommitted
Add missing mock for AppState (removeEventListener)
Summary: I am testing with Jest a component that use [AppState.removeEventListener](https://facebook.github.io/react-native/docs/appstate.html#removeeventlistener) and I am currently facing a fatal error saying that `AppState.removeEventListener` is `undefined`. Create a component that uses `AppState`, e.g. ```jsx import React, { Component } from 'react'; import { AppState } from 'react-native'; class TestComponent extends Component { componentDidMount() { AppState.addEventListener('change', this.stateChangeListener); } componentWillUnmount() { AppState.removeEventListener('change', this.stateChangeListener); } } ``` It should pass test using Jest (snapshots) It's the continuation of facebook#11199. This PR finish the mock for the native module `AppState`. [ GENERAL ] [ BUGFIX ] [AppState] Add missing mock for Jest for `removeEventListener` method. Closes facebook#17908 Differential Revision: D7083144 Pulled By: shergin fbshipit-source-id: eafa07f064f971c3d657f2ffc9c00766c0925bac
1 parent d2817f4 commit 59c7b2c

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

jest/setup.js

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ const mockNativeModules = {
113113
},
114114
AppState: {
115115
addEventListener: jest.fn(),
116+
removeEventListener: jest.fn(),
116117
},
117118
AsyncLocalStorage: {
118119
multiGet: jest.fn((keys, callback) => process.nextTick(() => callback(null, []))),

0 commit comments

Comments
 (0)