mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-02 05:18:12 +08:00
934cc5c69b
* Added TS. Updated build and linting config. Added types. * [ts-migrate][.] Rename files from JS/JSX to TS/TSX Co-authored-by: ts-migrate <> * [ts-migrate][.] Run TS Migrate Co-authored-by: ts-migrate <> * Corrected files mangled by ts-migrate. * Updated lint config, minor linting. * Re-enabled Husky. * Updated tests and config. * Reverted webpack devtool config. * Removed obsolete snapshots. * Added annotations snap. * Updated tsconfig includes wrt linting. * Removed ts-migrate. Co-authored-by: Timmy Huang <tihuan@users.noreply.github.com>
59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
import cascadeReducers from "../../src/reducers/cascade";
|
|
|
|
describe("create", () => {
|
|
test("from Array", () => {
|
|
expect(cascadeReducers([["foo", () => 0]])).toBeInstanceOf(Function);
|
|
});
|
|
|
|
test("from Map", () => {
|
|
expect(cascadeReducers(new Map([["foo", () => 0]]))).toBeInstanceOf(
|
|
Function
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("cascade", () => {
|
|
test("expected arguments provided & cascade ordering", () => {
|
|
const topLevelState = {};
|
|
const topLevelAction = { type: "test" };
|
|
|
|
const reducer = cascadeReducers([
|
|
[
|
|
"foo",
|
|
(
|
|
currentState: any,
|
|
action: any,
|
|
nextSharedState: any,
|
|
prevSharedState: any
|
|
) => {
|
|
expect(currentState).toBeUndefined();
|
|
expect(action).toEqual(topLevelAction);
|
|
expect(nextSharedState).toStrictEqual({});
|
|
expect(prevSharedState).toBe(topLevelState);
|
|
return 0;
|
|
},
|
|
],
|
|
[
|
|
"bar",
|
|
(
|
|
currentState: any,
|
|
action: any,
|
|
nextSharedState: any,
|
|
prevSharedState: any
|
|
) => {
|
|
expect(currentState).toBeUndefined();
|
|
expect(action).toEqual(topLevelAction);
|
|
expect(nextSharedState).toStrictEqual({ foo: 0 });
|
|
expect(prevSharedState).toBe(topLevelState);
|
|
return 99;
|
|
},
|
|
],
|
|
]);
|
|
|
|
const nextState = reducer(topLevelState, topLevelAction);
|
|
expect(nextState).toStrictEqual({ foo: 0, bar: 99 });
|
|
expect(topLevelState).toStrictEqual({});
|
|
expect(topLevelAction).toStrictEqual({ type: "test" });
|
|
});
|
|
});
|