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);