我有一个组件在它的componentDidMount方法中多次设置状态。例如:
componentDidMount = async () => {
this.setState({ waiting: true });
try {
const data = await this.fetchData();
this.setState({ data })
} catch (err) {
} finally {
this.setState({ waiting: false });
}
};使用类似于:
render() {
if (this.state.waiting) {
return (
<View style={{ flex: 1 }}>
<ActivityIndicator size="large" />
</View>
);
}
return (
... actual view ...
)
}我可以用react-native-testing-library进行测试
const tree = testing.render(<HomeScreen {...props} />);但我却只能看到等待的景色。但是,当我通过测试时,另一个呈现就会被击中。
因此,快照测试似乎只捕获第一个呈现。有没有办法让它给我最后的渲染?
发布于 2019-10-26 01:40:30
结果我需要等待微任务。
await testing.flushMicrotasksQueue();成功了
https://stackoverflow.com/questions/58567243
复制相似问题