HS tests: innerHTML/textContent clears children in mock DOM

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) <noreply@anthropic.com>
This commit is contained in:
2026-04-14 12:47:34 +00:00
parent a6eb125dcc
commit 23e8379622

View File

@@ -1663,12 +1663,29 @@ let run_spec_tests env test_files =
in in
Hashtbl.replace d key stored; Hashtbl.replace d key stored;
(* Side effects for special keys *) (* Side effects for special keys *)
(if key = "className" then (match key with
match Hashtbl.find_opt d "classList" with | "className" ->
| Some (Dict cl) -> (match Hashtbl.find_opt d "classList" with
(* classList sub-dict doesn't store classes — they live in className *) | Some (Dict _cl) -> () (* classes live in className *)
ignore cl | _ -> ())
| _ -> ()); | "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 stored
| _ -> Nil); | _ -> Nil);