【发布时间】:2018-04-19 14:17:32
【问题描述】:
我正在尝试测试是否在我的 React Native 项目中从 componentDidMount 调用了调度。 我的问题是我不知道如何检查是否调用了 autoLogin()。
test.js
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
const mockStore = configureMockStore([thunk]);
it('should be called once', () => {
const wrapper = shallow(<SplashScreen store={mockStore()} />).dive();
});
index.js
class SplashScreen extends Component {
componentDidMount() {
this.props.autoLogin();
}
}
export default connect(null, { autoLogin })(SplashScreen);
【问题讨论】:
-
请添加
mockStore函数的代码。 -
我已经添加了您要求的代码。
标签: react-native react-redux jestjs enzyme redux-mock-store