Adding Jest Mocks
See original GitHub issueDescription
Through-out the various apps I work on, we always end up writing jest mocks for this lib.
Is there any opposition to adding file like <root>/jest/react-native-device-info-mock.js
that can be imported into an app’s jest setup ?
There are a few other libs that follow a similar approach:
Use Case
As mentioned in various other issues related to mocks, this would greatly improve Developer Experience
.
If we’re cool with it, I can make a PR adding it.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Manual Mocks - Jest
When a manual mock exists for a given module, Jest's module system will use that module when explicitly calling jest.mock('moduleName') .
Read more >A guide to module mocking with Jest - Emma Goto
A guide to module mocking with Jest · Mocking a named import · Mocking only the named import (and leaving other imports unmocked)...
Read more >Mocking ES and CommonJS modules with jest.mock() - Medium
Jest will automatically hoist jest.mock calls to the top of the module (before any imports). Since calls to jest.mock() are hoisted to the...
Read more >How To Mock Dependencies With Jest
Instead of mocking every function, jest helps us mimic the entire module using jest.mock. Create mocks directory into the same path of the...
Read more >jest-mock - npm
Note:** More details on user side API can be found in [Jest documentation](https://jestjs.io/docs/mock-function-api).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
hello,
i tried to use the mocks (by registrating it in the jest setup file) to change the return value of the hasNotch function but I can not get it working especially when doing two tests with different return values.
Is there a way you could provide an example usage for the mocks where you change the return value of a device info?
My Code: in setup setup.js
Thank you, this worked well for me! @sem4phor