【发布时间】:2019-11-20 09:12:02
【问题描述】:
我有一个看起来像这样的组件
async componentDidMount() {
const { navigation } = this.props
this.subs = [
navigation.addListener('didFocus', () => this.onComponentFocus()),
]
}
onComponentFocus() {
const { dispatch } = this.props
dispatch(fetchDevices())
}
现在我想编写一个测试 chekcs fetchDevice 被调用一次。第一个想法是像这样模拟 Navigation
常量导航 = { 导航:jest.fn(), }
但是现在我该如何检查 this.subs 以及如何检查 fetchDevices 被解雇了?
【问题讨论】:
-
这取决于
fetchDevices()来自哪里
标签: react-native jestjs react-navigation