From dbc87e86f99a7a89c69c8746f177091dafabb9bd Mon Sep 17 00:00:00 2001 From: SGavrl <277843151+SGavrl@users.noreply.github.com> Date: Sat, 1 Aug 2026 15:37:17 +0000 Subject: [PATCH] test(js): cover string timer handlers --- crates/obscura-js/src/runtime.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/crates/obscura-js/src/runtime.rs b/crates/obscura-js/src/runtime.rs index fdfeb4d..ccf8e1e 100644 --- a/crates/obscura-js/src/runtime.rs +++ b/crates/obscura-js/src/runtime.rs @@ -1317,6 +1317,35 @@ mod tests { rt } + #[tokio::test(flavor = "current_thread")] + async fn string_timeout_handler_executes_in_global_scope() { + let mut rt = setup_runtime(""); + rt.evaluate( + "var __timerValue='pending'; setTimeout('__timerValue=\"done\"', 0)", + ) + .unwrap(); + rt.run_event_loop_bounded(100).await.unwrap(); + assert_eq!( + rt.evaluate("globalThis.__timerValue").unwrap(), + serde_json::json!("done") + ); + } + + #[tokio::test(flavor = "current_thread")] + async fn string_interval_handler_repeats_and_can_clear_itself() { + let mut rt = setup_runtime(""); + rt.evaluate("globalThis.__ticks=0").unwrap(); + rt.evaluate( + "globalThis.__timerId=setInterval('__ticks++;if(__ticks===2)clearInterval(__timerId)',1)", + ) + .unwrap(); + rt.run_event_loop_bounded(100).await.unwrap(); + assert_eq!( + rt.evaluate("globalThis.__ticks").unwrap(), + serde_json::json!(2.0) + ); + } + #[test] fn test_document_title() { let mut rt = setup_runtime("Test");