release: WRNexusJS 0.4.0

This commit is contained in:
2026-07-27 12:42:18 +05:30
parent 8b728a3e5d
commit 30e5721e84
250 changed files with 10065 additions and 3923 deletions
+33 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, test } from "bun:test";
import { batch, computed, effect, signal } from "../src/index.ts";
import { batch, computed, effect, resource, signal, watch } from "../src/index.ts";
describe("reactive primitives", () => {
test("signals skip no-op updates", () => {
@@ -45,3 +45,35 @@ describe("reactive primitives", () => {
expect(seen).toEqual([0, 1]);
});
});
test("watch reports undefined as the previous value for an immediate run", () => {
const value = signal(1);
const seen: Array<[number, number | undefined]> = [];
const stop = watch(
() => value.get(),
(next, previous) => void seen.push([next, previous]),
{ immediate: true },
);
value.set(2);
stop();
expect(seen).toEqual([
[1, undefined],
[2, 1],
]);
});
test("aborting a pending resource does not dereference a cleared controller", async () => {
let resolve!: (value: string) => void;
const pending = new Promise<string>((done) => {
resolve = done;
});
const value = resource(() => pending);
const run = value.run();
value.abort("cancelled");
resolve("late");
await expect(run).resolves.toBeUndefined();
expect(value.status.get()).toBe("idle");
expect(value.data.get()).toBeUndefined();
});