【发布时间】:2018-12-31 01:55:59
【问题描述】:
我们如何在一个阶段测试state 变量的变化,这意味着我想测试的不是最终结果,而是两者之间的结果。
下面是我要测试的代码。
onLogin = () => {
this.setState({ isLoggingIn: true }, () => {
try {
} catch (err) {
// Alert.alert(getString('ERROR'), err.message);
} finally {
this.setState({ isLoggingIn: false });
}
});
}
下面是我的测试代码。
it('should call onLogin callback', () => {
const spy = jest.spyOn(wrapper.instance(), 'onLogin');
const loginBtn = wrapper.find('#login');
loginBtn.props().onPress();
expect(spy).toHaveBeenCalled();
expect(wrapper.instance().state.isLoggingIn).toEqual(false);
// Attempt => Below I've tried
// wrapper.update();
// expect(wrapper.instance().state.isLoggingIn).toEqual(true);
// wrapper.update();
// expect(wrapper.instance().state.isLoggingIn).toEqual(false);
wrapper.instance().state.isLoggingIn 始终为假。如何监控对false 然后true 的更改?
【问题讨论】:
标签: react-native jestjs enzyme