react-native - 如何在 react-native-router-flux 中模拟 Actions 的 Scene 键?
问题描述
我正在尝试测试按钮按下是否会调用Actions.sceneKey();
我尝试使用它来模拟它
jest.mock(
'react-native-router-flux', () => ({
Actions: {
sceneKey: jest.fn(),
},
})
);
但是当这段代码运行时:
test('enter received code', () => {
const { getByPlaceholderText, getByText } = render(
<EnterCode />
);
const button = getByText('confirm');
fireEvent.press(button);
expect(button).toBeTruthy();
expect(Actions.sceneKey).toBeCalledTimes(1);
});
它说
expect(jest.fn()).toBeCalledTimes(expected)
Expected number of calls: 1
Received number of calls: 0
> 45 | expect(Actions.sceneKey).toBeCalledTimes(1);
同样在我的组件中,我的 onPress 回调中有这个函数:
<Button
onPress={() => {
Actions.sceneKey();
}}
text="confirm"
/>
另外,由于我是新来测试一个更重要的问题是我什至需要测试场景转换功能吗?
解决方案
推荐阅读
- python - 如何解密使用烧瓶中的 generate_hash_password 函数加密的密码
- javascript - window.open() 仅适用于输入类型,但不适用于标签?
- r - 在R中通过集群计算最佳路径的有效方法
- vue.js - 出现错误时重定向到 Vue 中的另一个组件
- list - Haskell 中是否有像“uniqueBy”一样工作的函数?
- javascript - 从 chrome.executeScript 执行 QuerySelector
- vue.js - 多个 Vue.js 站点/NGINX 反向代理/热重载不起作用
- html - 如何在我的情况下水平居中项目?
- python - 如何将已删除项目的数量添加回我在 django 的总数量中?
- flutter - 带有导航栏项的活动状态颤动的圆形背景