@aics/ redux- utils
这个软件包抽取国家管理和测试公用事业 饼干- 反应- 红色 和别处.
所有函数,类和接口均从本软件包的顶层导出. 没有默认导出 。 例如:
import { configureMockStore, ResponseStub, makeReducer } from "@aics/redux-utils";
实例:
- 测试a
redux-logic逻辑响应一个动作,提出HTTP请求,并随HTTP请求的结果发出另一个动作. 为响应HTTP请求提供模拟值.
import { configureMockStore } from "@aics/redux-utils";
import { expect } from "chai";
describe("configureMockStore", () => {
interface State {
foo: string;
bar: number;
}
const initialState = {
foo: "hello",
bar: 123,
};
const simpleReducer: Reducer = (state = initialState, action) => {
if (action.payload) {
return {
...state,
...action.payload,
};
}
return state;
};
const logic = createLogic({
type: "TEST1",
process: async (deps, dispatch, done) {
const response = await deps.httpClient.get("/api/1.0/foo/bar");
dispatch({ type: "TEST3", payload: response.data });
done();
},
});
const responseStub = {
when: "/api/1.0/foo/bar",
respondWith: { data: "Hello from the endpoint" },
};
// DON'T MISS THE ASYNC!
it("creates a mock Redux store with some helpful defaults and utilies", async () => {
const { store, actions, logicMiddleware } = configureMockStore<State>({
state: initialState,
reducer: simpleReducer,
responseStubs: [responseStub]
logics: [logic],
});
store.dispatch({ type: "TEST1" });
// AFTER THIS POINT, ALL LOGICS HAVE FINISHED RUNNING
await logicMiddleware.whenComplete();
expect(actions.includes({ type: "TEST1" })).to.be.true;
// dispatched by logic
expect(actions.includes({ type: "TEST3", payload: "Hello from the endpoint" })).to.be.true;
});
});
出口
动作
-
函数 :
- [批量动作]]
- [可切入]]
-
接口 :
- [批量行动]]
动作跟踪器
-
类 :
- [行动跟踪器]]
-
接口 :
- [行动]
常数
- 函数 :
- [[恒 ]
模拟- http客户端
-
职能
- [[创建MockHttclient]]
-
接口
- [[答复站
模拟存储
-
职能
- [[构型MockStore]]]
-
接口
- [构图存储连接]]
减少数
-
职能
- [制作减
-
接口
- [行动手 ]
- [行动TypeThandlerMap]]
状态
- 职能
- [[合并状态]]
存储
-
职能
- [构型站 ]
-
常数
- [默认ReduxLogicDeps]]
-
接口 :
- [构图堆肥]]
- [ReduxLogic Dependencys]] (中文(简体) )