如何通过玩笑来测试反应导航中的'didFocus'>>

问题描述 投票:0回答:1

我有一个看起来像这样的组件

async componentDidMount() {
    const { navigation } = this.props
    this.subs = [
      navigation.addListener('didFocus', () => this.onComponentFocus()),
    ]
  }

  onComponentFocus() {
    const { dispatch } = this.props
    dispatch(fetchDevices())
  }

现在,我想编写一个测试一次,让chekcs fetchDevice被调用一次。第一个想法是像这样模拟导航

常量导航= {导航:jest.fn(),}

但是现在我如何检查this.subs,以及如何检查fetchDevices被解雇了?

我有一个看起来像这样的组件componentDidMount(){const {navigation} = this.props this.subs = [navigation.addListener('didFocus',()=> this.onComponentFocus()),...

react-native jestjs react-navigation
1个回答
0
投票

如果我们假设fetchDevices来自库

© www.soinside.com 2019 - 2024. All rights reserved.