pub struct Clock { /* private fields */ }Expand description
A fake-timer handle for a Page.
Cheaply cloneable; all clones share the same page session and controller.
Implementations§
Source§impl Clock
impl Clock
Sourcepub async fn install(&self, options: Option<ClockInstallOptions>) -> Result<()>
pub async fn install(&self, options: Option<ClockInstallOptions>) -> Result<()>
Engage the fake timers: installs the controller over Date,
performance.now, and the timer functions, then optionally pins the
time. Call this before the code under test schedules any timers.
Sourcepub async fn set_fixed_time(&self, time: Option<i64>) -> Result<()>
pub async fn set_fixed_time(&self, time: Option<i64>) -> Result<()>
Pin the virtual clock so Date.now()/new Date()/performance.now()
stop advancing. If time is Some(ms), the clock is also moved there
first; None fixes it at the current virtual time.
Calling this implicitly installs the controller if it is not present.
Sourcepub async fn advance(&self, ms: i64) -> Result<()>
pub async fn advance(&self, ms: i64) -> Result<()>
Advance the virtual clock by ms milliseconds, firing every timer that
falls due along the way (just like letting real time pass). Mirrors
Playwright’s clock.advance.
Sourcepub async fn tick(&self, ms: i64) -> Result<()>
pub async fn tick(&self, ms: i64) -> Result<()>
Advance the virtual clock by ms milliseconds without firing any
timers in between (they remain pending). Mirrors Playwright’s
clock.tick short-form (duration only).
Sourcepub async fn run_all(&self) -> Result<()>
pub async fn run_all(&self) -> Result<()>
Run all pending timers (microtasks/timers queued up to “now”) without
moving the clock. Mirrors Playwright’s clock.run_all.
Sourcepub async fn resume(&self) -> Result<()>
pub async fn resume(&self) -> Result<()>
Resume automatic (real) time progression on this page and clear all
fakes. Pending fake timers are discarded. Mirrors Playwright’s
clock.resume.
Sourcepub async fn resume_all(&self) -> Result<()>
pub async fn resume_all(&self) -> Result<()>
Alias for Clock::resume.