私はここに二つの質問を持っていますasync componentDidMount
React Nativeで非同期ComponentDidMountをテストするにはどうすればよいですか?
export class SplashContainer extends Component {
async componentDidMount() {
let token = await AsyncStorage.getItem('@XXX:token')
if (token !== null) {
await this.props.setTokenAvalability(true)
await this.props.getUserDetails()
}
await this.props.navToNextScreen()
}
render() {
return <Splash />
}
}
function mapDispatchToProps(dispatch) {
return {
navToNextScreen:() => dispatch(navToNextScreen(...)),
setTokenAvalability: (status) => dispatch(setTokenAvalability(status)),
getUserDetails:() => dispatch(getUserDetails()),
}
}
export default connect(null, mapDispatchToProps)(SplashContainer);
とSplashContainerを持っています。
。私がテストしたかったsetTokenAvalability and getUserDetails
が発送されているかどうかは分かりません。私は以下のように、非同期/待機がないかどうかをテストする方法を知っています。
it('test SplashContainer',() => {
const store = mockStore({});
const props = {
dispatch: store.dispatch
}
const tree = renderer.create(
<SplashContainer {...props}/>
).toJSON();
const expectedAction = [
...
]
expect(store.getActions()).toEqual(expectedAction);
});
。 AsyncStorage.getItem()
おかげで、