Module clock

Module clock 

Source
Expand description

Clock mocking for controlling time in browser pages.

The Clock API allows you to control time-related functions in JavaScript, including Date, setTimeout, setInterval, requestAnimationFrame, and performance.now().

§Example

use std::time::Duration;

// Install clock mocking
page.clock().install().await.unwrap();

// Set a fixed time
page.clock().set_fixed_time("2024-01-01T00:00:00Z").await.unwrap();

// Check that Date.now() returns the fixed time
use viewpoint_js::js;
let time: f64 = page.evaluate(js!{ Date.now() }).await.unwrap();

// Advance time by 5 seconds, firing any scheduled timers
page.clock().run_for(Duration::from_secs(5)).await.unwrap();

Structs§

Clock
Clock controller for mocking time in a browser page.

Enums§

TimeValue
A time value that can be either a timestamp or an ISO string.