当然
可能的
要通过重击实现此功能:
export const dragOverAction = function(payload: DragOverActionPayload) {
return function(dispatch: Dispatch, getState: () => GlobalStateTree) {
// Various business logic
if (someCondition) {
return;
}
if (anotherCondition) {
dispatch(doSomething({
<snip>
}));
} else if (anotherCondition) {
dispatch(doSomethingElse({
<snip>
}));
}
// Otherwise, don't dispatch anything.
}
}
测试并没有我预想的那么糟糕:
import configureMockStore from "redux-mock-store";
import thunk from "redux-thunk";
export const mockStore = configureMockStore([thunk]);
import * as allActions from "../app/actions/index";
describe("dragOverAction", function() {
it("should <blah blah>", async function() {
let store = mockStore();
await store.dispatch<any>(allActions.dragOverAction({
foo: bar,
<snip>
}));
const actions = store.getActions();
expect(actions).toBe(<snip>);
});
});