From 2aba3522ab7dfe113ec26131b747f7f6f0486194 Mon Sep 17 00:00:00 2001 From: Adrian Hartanto Date: Fri, 16 Sep 2022 08:54:05 -0700 Subject: [PATCH] fix: adjust clipboard mock (#34672) Summary: Currently, Clipboard's methods (setString, getString) can't be asserted when writing tests as the mock targeted `Libraries/BatchedBridge/NativeModules` instead of `Libraries/Components/Clipboard/Clipboard` that's used on react-native [entry point](https://github.com/facebook/react-native/blob/main/index.js#L270) so it won't be considered as `mock function`. ## Changelog [General] [Changed] - Update `Clipboard` mock path Pull Request resolved: https://github.com/facebook/react-native/pull/34672 Test Plan: ```js // App-test.js import { Clipboard } from 'react-native'; import React from 'react'; it('renders correctly', () => { Clipboard.setString('string'); expect(Clipboard.setString).toBeCalled(); }); ``` ### before Screen Shot 2022-09-13 at 16 24 30 ### after Screen Shot 2022-09-13 at 16 26 34 Reviewed By: yungsters Differential Revision: D39575916 Pulled By: cortinico fbshipit-source-id: 34a3f93986a18d349ac033bb13a10ed77689935c --- jest/setup.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jest/setup.js b/jest/setup.js index baacd7ebef4e79..3738bd2c61e516 100644 --- a/jest/setup.js +++ b/jest/setup.js @@ -135,6 +135,10 @@ jest getRecommendedTimeoutMillis: jest.fn(), }, })) + .mock('../Libraries/Components/Clipboard/Clipboard', () => ({ + getString: jest.fn(() => ''), + setString: jest.fn(), + })) .mock('../Libraries/Components/RefreshControl/RefreshControl', () => jest.requireActual( '../Libraries/Components/RefreshControl/__mocks__/RefreshControlMock', @@ -201,10 +205,6 @@ jest process.nextTick(() => callback(null, [])), ), }, - Clipboard: { - getString: jest.fn(() => ''), - setString: jest.fn(), - }, DeviceInfo: { getConstants() { return {