2020-01-03 01:04:41 +00:00
|
|
|
import Updux from ".";
|
|
|
|
import u from "updeep";
|
2019-10-23 21:54:37 +00:00
|
|
|
|
|
|
|
const noopEffect = () => () => () => {};
|
|
|
|
|
2020-01-03 01:04:41 +00:00
|
|
|
test.only("actions defined in effects and mutations, multi-level", () => {
|
|
|
|
const { actions } = new Updux({
|
2019-10-23 21:54:37 +00:00
|
|
|
effects: {
|
2020-01-03 01:04:41 +00:00
|
|
|
foo: noopEffect
|
2019-10-23 21:54:37 +00:00
|
|
|
},
|
2020-01-03 01:04:41 +00:00
|
|
|
mutations: { bar: () => () => null },
|
2019-10-23 21:54:37 +00:00
|
|
|
subduxes: {
|
|
|
|
mysub: {
|
2020-01-03 01:04:41 +00:00
|
|
|
effects: { baz: noopEffect },
|
|
|
|
mutations: { quux: () => () => null },
|
2019-10-23 21:54:37 +00:00
|
|
|
actions: {
|
2020-01-03 01:04:41 +00:00
|
|
|
foo: (limit: number) => ({ limit })
|
|
|
|
}
|
2019-10-23 21:54:37 +00:00
|
|
|
},
|
|
|
|
myothersub: {
|
|
|
|
effects: {
|
2020-01-03 01:04:41 +00:00
|
|
|
foo: noopEffect
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-10-23 21:54:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const types = Object.keys(actions);
|
|
|
|
types.sort();
|
|
|
|
|
2020-01-03 01:04:41 +00:00
|
|
|
expect(types).toEqual(["bar", "baz", "foo", "quux"]);
|
2019-10-23 21:54:37 +00:00
|
|
|
|
2020-01-03 01:04:41 +00:00
|
|
|
expect(actions.bar()).toEqual({ type: "bar" });
|
|
|
|
expect(actions.bar("xxx")).toEqual({ type: "bar", payload: "xxx" });
|
|
|
|
expect(actions.bar(undefined, "yyy")).toEqual({ type: "bar", meta: "yyy" });
|
2019-10-23 21:54:37 +00:00
|
|
|
|
2020-01-03 01:04:41 +00:00
|
|
|
expect(actions.foo(12)).toEqual({ type: "foo", payload: { limit: 12 } });
|
2019-10-23 21:54:37 +00:00
|
|
|
});
|