From cb8afda183e9c931978279d3a1706d1d9c905484 Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Thu, 8 Jul 2021 23:01:29 -0400 Subject: [PATCH] Add test for #21837 (#21842) Taken from https://github.com/facebook/react/pull/21837#issuecomment-876788973 Co-Authored-By: Timothy Yung Co-authored-by: Timothy Yung --- .../__tests__/ReactFabric-test.internal.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js b/packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js index 4c5bea872bbd8..6b776c085fd40 100644 --- a/packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js +++ b/packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js @@ -1064,4 +1064,36 @@ describe('ReactFabric', () => { expect(TextInputState.focusTextInput).toHaveBeenCalledTimes(1); expect(TextInputState.focusTextInput).toHaveBeenCalledWith(viewRef.current); }); + + it('should no-op if calling sendAccessibilityEvent on unmounted refs', () => { + const View = createReactNativeComponentClass('RCTView', () => ({ + validAttributes: {foo: true}, + uiViewClassName: 'RCTView', + })); + + nativeFabricUIManager.sendAccessibilityEvent.mockReset(); + + let viewRef; + act(() => { + ReactFabric.render( + { + viewRef = ref; + }} + />, + 11, + ); + }); + const dangerouslyRetainedViewRef = viewRef; + act(() => { + ReactFabric.stopSurface(11); + }); + + ReactFabric.sendAccessibilityEvent( + dangerouslyRetainedViewRef, + 'eventTypeName', + ); + + expect(nativeFabricUIManager.sendAccessibilityEvent).not.toBeCalled(); + }); });