@praxisjs/runtime 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/__tests__/children.test.d.ts +2 -0
- package/dist/__tests__/children.test.d.ts.map +1 -0
- package/dist/__tests__/children.test.js +87 -0
- package/dist/__tests__/children.test.js.map +1 -0
- package/dist/__tests__/component.test.d.ts +2 -0
- package/dist/__tests__/component.test.d.ts.map +1 -0
- package/dist/__tests__/component.test.js +134 -0
- package/dist/__tests__/component.test.js.map +1 -0
- package/dist/__tests__/context.test.d.ts +2 -0
- package/dist/__tests__/context.test.d.ts.map +1 -0
- package/dist/__tests__/context.test.js +43 -0
- package/dist/__tests__/context.test.js.map +1 -0
- package/dist/__tests__/dom.test.d.ts +2 -0
- package/dist/__tests__/dom.test.d.ts.map +1 -0
- package/dist/__tests__/dom.test.js +174 -0
- package/dist/__tests__/dom.test.js.map +1 -0
- package/dist/__tests__/render.test.d.ts +2 -0
- package/dist/__tests__/render.test.d.ts.map +1 -0
- package/dist/__tests__/render.test.js +73 -0
- package/dist/__tests__/render.test.js.map +1 -0
- package/dist/__tests__/scope.test.d.ts +2 -0
- package/dist/__tests__/scope.test.d.ts.map +1 -0
- package/dist/__tests__/scope.test.js +56 -0
- package/dist/__tests__/scope.test.js.map +1 -0
- package/package.json +4 -4
- package/src/__tests__/children.test.ts +99 -0
- package/src/__tests__/component.test.ts +148 -0
- package/src/__tests__/context.test.ts +53 -0
- package/src/__tests__/dom.test.ts +202 -0
- package/src/__tests__/render.test.ts +89 -0
- package/src/__tests__/scope.test.ts +62 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { Scope } from "../scope";
|
|
4
|
+
|
|
5
|
+
describe("Scope", () => {
|
|
6
|
+
it("add() registers a cleanup fn that runs on dispose()", () => {
|
|
7
|
+
const scope = new Scope();
|
|
8
|
+
const cleanup = vi.fn();
|
|
9
|
+
scope.add(cleanup);
|
|
10
|
+
scope.dispose();
|
|
11
|
+
expect(cleanup).toHaveBeenCalledOnce();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("dispose() runs all cleanups in order", () => {
|
|
15
|
+
const scope = new Scope();
|
|
16
|
+
const order: number[] = [];
|
|
17
|
+
scope.add(() => order.push(1));
|
|
18
|
+
scope.add(() => order.push(2));
|
|
19
|
+
scope.add(() => order.push(3));
|
|
20
|
+
scope.dispose();
|
|
21
|
+
expect(order).toEqual([1, 2, 3]);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("dispose() clears cleanups — second dispose() is a no-op", () => {
|
|
25
|
+
const scope = new Scope();
|
|
26
|
+
const fn = vi.fn();
|
|
27
|
+
scope.add(fn);
|
|
28
|
+
scope.dispose();
|
|
29
|
+
scope.dispose();
|
|
30
|
+
expect(fn).toHaveBeenCalledOnce();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("effect() registers a reactive effect and its cleanup", () => {
|
|
34
|
+
const scope = new Scope();
|
|
35
|
+
const ran: number[] = [];
|
|
36
|
+
scope.effect(() => {
|
|
37
|
+
ran.push(1);
|
|
38
|
+
});
|
|
39
|
+
expect(ran).toHaveLength(1); // runs immediately
|
|
40
|
+
scope.dispose();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("fork() creates a child scope that disposes when parent disposes", () => {
|
|
44
|
+
const parent = new Scope();
|
|
45
|
+
const child = parent.fork();
|
|
46
|
+
const childCleanup = vi.fn();
|
|
47
|
+
child.add(childCleanup);
|
|
48
|
+
parent.dispose();
|
|
49
|
+
expect(childCleanup).toHaveBeenCalledOnce();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("fork() child can be disposed independently before parent", () => {
|
|
53
|
+
const parent = new Scope();
|
|
54
|
+
const child = parent.fork();
|
|
55
|
+
const childFn = vi.fn();
|
|
56
|
+
child.add(childFn);
|
|
57
|
+
child.dispose();
|
|
58
|
+
expect(childFn).toHaveBeenCalledOnce();
|
|
59
|
+
// parent dispose should not throw even though child is already disposed
|
|
60
|
+
expect(() => { parent.dispose(); }).not.toThrow();
|
|
61
|
+
});
|
|
62
|
+
});
|