Skip to content

Commit

Permalink
Add Vibration module mock (#30643)
Browse files Browse the repository at this point in the history
Summary:
I wrote a test for a vibration feature in a react native app by importing the `Vibration` module and using `jest.spyOn(Vibration, 'vibrate')`.

I had the following error:
```
Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'Vibration' could not be found. Verify that a module by this name is registered in the native binary.
```

That lead me to look for (and not find) a mock for the `Vibration` module in the code.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[General] [Fixed] - Add Jest mock for Vibration module

Pull Request resolved: #30643

Test Plan:
I would be glad to provide a test plan for this, but as it is part of testing I don't really know how to do so.
Any suggestion or help is welcome!

Reviewed By: yungsters

Differential Revision: D36097003

Pulled By: cortinico

fbshipit-source-id: 58683120da34f40e142a44c4bef8a5fced04bac2
  • Loading branch information
hduprat authored and facebook-github-bot committed May 3, 2022
1 parent a649675 commit 79529a1
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions jest/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,10 @@ jest
'../Libraries/Utilities/verifyComponentAttributeEquivalence',
() => function () {},
)
.mock('../Libraries/Vibration/Vibration', () => ({
vibrate: jest.fn(),
cancel: jest.fn(),
}))
.mock('../Libraries/Components/View/ViewNativeComponent', () => {
const React = require('react');
const Component = class extends React.Component {
Expand Down

0 comments on commit 79529a1

Please # to comment.