From 59c7b2cfac534a79ff2461af5fd2034b280812a3 Mon Sep 17 00:00:00 2001 From: Maxime Thirouin <157534+moox@users.noreply.github.com> Date: Sun, 25 Feb 2018 21:55:18 -0800 Subject: [PATCH] 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 #11199. This PR finish the mock for the native module `AppState`. [ GENERAL ] [ BUGFIX ] [AppState] Add missing mock for Jest for `removeEventListener` method. Closes https://github.com/facebook/react-native/pull/17908 Differential Revision: D7083144 Pulled By: shergin fbshipit-source-id: eafa07f064f971c3d657f2ffc9c00766c0925bac --- jest/setup.js | 1 + 1 file changed, 1 insertion(+) diff --git a/jest/setup.js b/jest/setup.js index 628555043..680e391ba 100644 --- a/jest/setup.js +++ b/jest/setup.js @@ -113,6 +113,7 @@ const mockNativeModules = { }, AppState: { addEventListener: jest.fn(), + removeEventListener: jest.fn(), }, AsyncLocalStorage: { multiGet: jest.fn((keys, callback) => process.nextTick(() => callback(null, []))),