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:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user