From 719588ffe25a49b83c7f6ad6edb6aae72fe8222c Mon Sep 17 00:00:00 2001 From: le king fu Date: Fri, 23 Oct 2026 21:12:31 -0400 Subject: [PATCH] test: prove that holding never calls a component either (#467) Self-review: the docblock says that neither helper calls a component of the tree, but only find had a test for it. holding gets its own (a holder that a child component renders is not found, the component is never called). The header no longer reads as if no test file kept a copy of its own: several still do. Resolves #467 Co-Authored-By: Claude Opus 5.5 --- src/test/elementTree.test.ts | 8 ++++++++ src/test/elementTree.ts | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/test/elementTree.test.ts b/src/test/elementTree.test.ts index 328ede1..d2db6d9 100644 --- a/src/test/elementTree.test.ts +++ b/src/test/elementTree.test.ts @@ -113,6 +113,14 @@ describe("elementTree — holding", () => { expect(holding(beside, Trash2)).toEqual([]); }); + it("never calls a component of the tree: a holder its child renders is not there", () => { + const Child = vi.fn(() => h("button", { id: "inside" }, h(Trash2))); + const node = h("div", { id: "d" }, h(Child)); + expect(holding(node, Trash2)).toEqual([]); + expect(ids(holding(node, Child))).toEqual(["d"]); + expect(Child).not.toHaveBeenCalled(); + }); + it("lets a fragment hold its own children, not its parent", () => { const node = h("div", { id: "d" }, h(Fragment, null, h(Trash2))); const holders = holding(node, Trash2); diff --git a/src/test/elementTree.ts b/src/test/elementTree.ts index 6a517ba..fe4c378 100644 --- a/src/test/elementTree.ts +++ b/src/test/elementTree.ts @@ -2,8 +2,9 @@ // // A test that calls a component as a plain function, under the shared hook // harness of this folder or without it, gets back a tree of React elements, -// not a DOM. These two helpers search that tree; before #467, test files kept -// their own copy. Each semantic below is proved by elementTree.test.ts. +// not a DOM. These two helpers search that tree, shared since #467 (several +// test files still keep a copy of their own). Each semantic below is proved by +// elementTree.test.ts. // // - `find(node, pred)`: every element of the tree for which `pred` is true, // depth first: an element before what it holds, siblings in order, and an