How to mock this library with jest? (Fails when used normally)
See original GitHub issueEnvironment
Relevant versions:
"react": "17.0.2",
"react-native": "0.66.0",
"react-native-pager-view": "^5.4.9",
Description
Calling the setPage
method on a viewPager ref
causes jest to throw this error:
TypeError: Cannot read properties of undefined (reading 'Commands')
87 | if (viewPager.current) {
> 88 | viewPager.current.setPage(page);
| ^
89 | }
90 |
Reproducible Demo
- Create an integration test with any component using
ViewPager
and callsetPage
on it’s ref. This error will throw.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Manual Mocks - Jest
Manual mocks are used to stub out functionality with mock data. For example, instead of accessing a remote resource like a website or...
Read more >Jest: mocking console.error - tests fails - Stack Overflow
I wanted to mock console.error to count the number of times it was called by prop-types as I passed in missing/mis-typed props. Using...
Read more >Fail a test in Jest if an unexpected network request happens
We use axios to build our API requests. Any test that does a request that is not mocked should fail. It still should...
Read more >Testing & Error Handling (Jest, React Testing Library) - YouTube
Companies all over the world are using Next.js to build performant, scalable applications. In this video, we'll talk about.
Read more >React app testing: Jest and React Testing Library
Here, the test case is provided by Jest. For rendering and accessing the virtual DOM, we import and use both render and screen...
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
I extended the example with the public class methods and now it is working: