Skip to content

Commit

Permalink
fix: adjust clipboard mock (#34672)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
adrianha authored and facebook-github-bot committed Sep 16, 2022
1 parent 527ac2f commit 2aba352
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions jest/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -201,10 +205,6 @@ jest
process.nextTick(() => callback(null, [])),
),
},
Clipboard: {
getString: jest.fn(() => ''),
setString: jest.fn(),
},
DeviceInfo: {
getConstants() {
return {
Expand Down

0 comments on commit 2aba352

Please sign in to comment.