callstack / callstack/react-native-pager-view
How to mock this library with jest? (Fails when used normally)
- Dominant language
- TypeScript
- Stars
- 3.4k
- Forks
- 476
- Avg merge
- 10d 21h
- Merged PRs (30d)
- 2
Description
## Environment
Relevant versions:
```json
"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
1. Create an integration test with any component using `ViewPager` and call `setPage` on it's ref. This error will throw.
Contributor guide
Research direction
Start with the integration test described in the issue: render a component using ViewPager and call setPage on its ref. Investigate the Jest mock or test setup around the native ViewPager implementation and the undefined Commands error. Done means the test can call setPage without throwing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react-native
- Domain
- mobile, testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100