callstack / callstack/react-native-pager-view

How to mock this library with jest? (Fails when used normally)

未关闭
#481 7 条评论 8 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
TypeScript
星标
3.4k
派生
476
平均合并
10 天 21 小时
30 天内合并 PR
2

描述

## 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.

贡献指南

打开贡献指南

调研方向

从 issue 中描述的集成测试开始:使用 ViewPager 渲染一个组件,并在其 ref 上调用 setPage。调查 native ViewPager 实现周围的 Jest mock 或测试设置,以及 undefined Commands 错误。完成标准是测试可以调用 setPage 而不会抛出异常。

由索引模型根据 Issue 内容生成。

评估

技术栈
react-native
领域
mobile, testing-qa
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。