test(js): cover string timer handlers

This commit is contained in:
SGavrl committed 2026-08-01 15:37:17 +00:00
1 parent 3d39e59c14
commit dbc87e86f9
1 file changed
+29
+29
View File
@@ -1317,6 +1317,35 @@ mod tests {
rt rt
} }
#[tokio::test(flavor = "current_thread")]
async fn string_timeout_handler_executes_in_global_scope() {
let mut rt = setup_runtime("<html><body></body></html>");
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("<html><body></body></html>");
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] #[test]
fn test_document_title() { fn test_document_title() {
let mut rt = setup_runtime("<html><head><title>Test</title></head><body></body></html>"); let mut rt = setup_runtime("<html><head><title>Test</title></head><body></body></html>");