summaryrefslogtreecommitdiff
path: root/src/shapex.test.ts
diff options
context:
space:
mode:
authorAsko Nõmm <asko@nmm.ee>2025-04-18 19:24:23 +0300
committerAsko Nõmm <asko@nmm.ee>2025-04-18 19:24:23 +0300
commit8fa2077f292ed0fcabbdb01a436fc267fb16ae79 (patch)
tree2572ba5811d4de48d327cd2a038ccba490d4fc7f /src/shapex.test.ts
parent94f8cc415b7827b86d5c7bed3adf0b5c81b0e194 (diff)
Add state() helper method
Diffstat (limited to 'src/shapex.test.ts')
-rw-r--r--src/shapex.test.ts17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/shapex.test.ts b/src/shapex.test.ts
index 0e7b08d..35207bb 100644
--- a/src/shapex.test.ts
+++ b/src/shapex.test.ts
@@ -1,7 +1,7 @@
import { assertArrayIncludes, assertEquals } from "@std/assert";
import { assertSpyCall, spy } from "@std/testing/mock";
import { describe, it } from "@std/testing/bdd";
-import ShapeX, { EventCallback } from "./shapex.ts";
+import ShapeX, { type EventCallback } from "./shapex.ts";
describe("subscribe", () => {
it("subscribes to an event", () => {
@@ -364,4 +364,19 @@ describe("utility methods", () => {
assertEquals($.subscriptionCount("event1"), 2);
assertEquals($.subscriptionCount("event2"), 1);
});
+
+ it("returns updated state", () => {
+ const $ = ShapeX({ counter: 1 });
+
+ $.subscribe(
+ "event1",
+ (state) => ({ state: { counter: state.counter + 1 } }),
+ );
+
+ $.dispatch("event1");
+
+ assertEquals($.state(), {
+ counter: 2,
+ });
+ });
});