Skip to content

Commit 2aba352

Browse files
adrianhafacebook-github-bot
authored andcommitted
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 <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [General] [Changed] - Update `Clipboard` mock path Pull Request resolved: #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 <img width="473" alt="Screen Shot 2022-09-13 at 16 24 30" src="https://user-images.githubusercontent.com/5382429/189864957-6b926478-6781-4291-a1eb-4493779de1a2.png" /> ### after <img width="598" alt="Screen Shot 2022-09-13 at 16 26 34" src="https://user-images.githubusercontent.com/5382429/189865131-e7c39f97-1cc1-4eb9-b4c0-d9ddf7a05c9c.png" /> Reviewed By: yungsters Differential Revision: D39575916 Pulled By: cortinico fbshipit-source-id: 34a3f93986a18d349ac033bb13a10ed77689935c
1 parent 527ac2f commit 2aba352

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

jest/setup.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ jest
135135
getRecommendedTimeoutMillis: jest.fn(),
136136
},
137137
}))
138+
.mock('../Libraries/Components/Clipboard/Clipboard', () => ({
139+
getString: jest.fn(() => ''),
140+
setString: jest.fn(),
141+
}))
138142
.mock('../Libraries/Components/RefreshControl/RefreshControl', () =>
139143
jest.requireActual(
140144
'../Libraries/Components/RefreshControl/__mocks__/RefreshControlMock',
@@ -201,10 +205,6 @@ jest
201205
process.nextTick(() => callback(null, [])),
202206
),
203207
},
204-
Clipboard: {
205-
getString: jest.fn(() => ''),
206-
setString: jest.fn(),
207-
},
208208
DeviceInfo: {
209209
getConstants() {
210210
return {

0 commit comments

Comments
 (0)