我有一个像这样的基本反应组件。
import React from 'react';
import store from 'src/home/store';
class PageLoading extends React.Component {
constructor(props) {
super(props);
this.state = {
message: this.props.message
};
}
componentDidMount(){
store.dispatch({ type: 'SET_NOTIFICATION_DIALOG', status: '200', message: this.state.message, model: 'LOADING' });
}
render(){
return(<div />);
}
}
export default PageLoading;
如何统一这个组件..?
我正在使用 karma 和酶。我在下面的代码中写了这个,但这不起作用
import configureMockStore from 'redux-mock-store';
import PageLoading from 'src/home/components/PageLoading';
const middlewares = [];
const mockStore = configureMockStore(middlewares);
Enzyme.configure({ adapter: new Adapter() });
describe("Page Loading",()=>{
it("testing shoul dispatch action on calling componentdid mount",()=>{
const initialState = {}
const store = mockStore(initialState)
const wrapper = mount(<PageLoading message="loading"/>);
const actions = store.getActions();
const expectedPayload = {type: 'SET_NOTIFICATION_DIALOG', status: '200', message:"loading", model: 'LOADING' };
expect(actions).toEqual([expectedPayload])
})
})
我认为它没有进入商店。