From 23e83796226444f15ec349f948de0c79eeb07ae0 Mon Sep 17 00:00:00 2001 From: giles Date: Tue, 14 Apr 2026 12:47:34 +0000 Subject: [PATCH] HS tests: innerHTML/textContent clears children in mock DOM MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Setting innerHTML="" on a mock element now detaches and removes all children, matching browser behavior. Previously hs-cleanup! (which sets body.innerHTML="") left stale children attached, causing querySelector to find elements from prior tests. Also clears children when textContent is set (browser behavior). 375 → 393/831 HS tests (+18). Co-Authored-By: Claude Opus 4.6 (1M context) --- hosts/ocaml/bin/run_tests.ml | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/hosts/ocaml/bin/run_tests.ml b/hosts/ocaml/bin/run_tests.ml index 24ec68b1..ba3f43fa 100644 --- a/hosts/ocaml/bin/run_tests.ml +++ b/hosts/ocaml/bin/run_tests.ml @@ -1663,12 +1663,29 @@ let run_spec_tests env test_files = in Hashtbl.replace d key stored; (* Side effects for special keys *) - (if key = "className" then - match Hashtbl.find_opt d "classList" with - | Some (Dict cl) -> - (* classList sub-dict doesn't store classes — they live in className *) - ignore cl - | _ -> ()); + (match key with + | "className" -> + (match Hashtbl.find_opt d "classList" with + | Some (Dict _cl) -> () (* classes live in className *) + | _ -> ()) + | "innerHTML" -> + (* Setting innerHTML clears children (like a real browser) *) + (match stored with + | String "" -> + (* Detach children *) + let kids = match Hashtbl.find_opt d "children" with Some (List l) -> l | _ -> [] in + List.iter (fun c -> match c with Dict cd -> + Hashtbl.replace cd "parentElement" Nil; + Hashtbl.replace cd "parentNode" Nil | _ -> ()) kids; + Hashtbl.replace d "children" (List []); + Hashtbl.replace d "childNodes" (List []); + Hashtbl.replace d "textContent" (String "") + | _ -> ()) + | "textContent" -> + (* Setting textContent clears children *) + Hashtbl.replace d "children" (List []); + Hashtbl.replace d "childNodes" (List []) + | _ -> ()); stored | _ -> Nil);