Skip to content

Commit

Permalink
docs: iterate over the clock (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman committed Jun 3, 2024
1 parent 8975684 commit 8d0def1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 40 deletions.
67 changes: 34 additions & 33 deletions docs/src/api/class-clock.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,79 +87,79 @@ Tells `@sinonjs/fake-timers` to increment mocked time automatically based on the
Relevant only when using with [`option: shouldAdvanceTime`]. Increment mocked time by advanceTimeDelta ms every advanceTimeDelta ms change
in the real system time (default: 20).


## async method: Clock.next
## async method: Clock.jump
* since: v1.45
- returns: <[int]> Fake milliseconds since the unix epoch.

Advances the clock to the the moment of the first scheduled timer, firing it.
Advance the clock by jumping forward in time, firing callbacks at most once.
This can be used to simulate the JS engine (such as a browser) being put to sleep and resumed later, skipping intermediary timers.

**Usage**

```js
await page.clock.next();
await page.clock.jump(1000);
await page.clock.jump('30:00');
```

```python async
await page.clock.next()
await page.clock.jump(1000);
await page.clock.jump('30:00')
```

```python sync
page.clock.next()
page.clock.jump(1000);
page.clock.jump('30:00')
```

```java
page.clock().next();
page.clock().jump(1000);
page.clock().jump("30:00");
```

```csharp
await page.Clock.NextAsync();
await page.Clock.JumpAsync(1000);
await page.Clock.JumpAsync("30:00");
```

## async method: Clock.jump
### param: Clock.jump.time
* since: v1.45
- `time` <[int]|[string]>

Advance the clock by jumping forward in time, firing callbacks at most once. Returns fake milliseconds since the unix epoch.
This can be used to simulate the JS engine (such as a browser) being put to sleep and resumed later, skipping intermediary timers.
Time may be the number of milliseconds to advance the clock by or a human-readable string. Valid string formats are "08" for eight seconds, "01:00" for one minute and "02:34:10" for two hours, 34 minutes and ten seconds.

## async method: Clock.next
* since: v1.45
- returns: <[int]>

Advances the clock to the the moment of the first scheduled timer, firing it.
Returns fake milliseconds since the unix epoch.

**Usage**

```js
await page.clock.jump(1000);
await page.clock.jump('30:00');
await page.clock.next();
```

```python async
await page.clock.jump(1000);
await page.clock.jump('30:00')
await page.clock.next()
```

```python sync
page.clock.jump(1000);
page.clock.jump('30:00')
page.clock.next()
```

```java
page.clock().jump(1000);
page.clock().jump("30:00");
page.clock().next();
```

```csharp
await page.Clock.JumpAsync(1000);
await page.Clock.JumpAsync("30:00");
await page.Clock.NextAsync();
```

### param: Clock.jump.time
* since: v1.45
- `time` <[int]|[string]>

Time may be the number of milliseconds to advance the clock by or a human-readable string. Valid string formats are "08" for eight seconds, "01:00" for one minute and "02:34:10" for two hours, 34 minutes and ten seconds.

## async method: Clock.runAll
* since: v1.45
- returns: <[int]> Fake milliseconds since the unix epoch.
- returns: <[int]>

Runs all pending timers until there are none remaining. If new timers are added while it is executing they will be run as well.
Runs all pending timers until there are none remaining. If new timers are added while it is executing they will be run as well. Returns fake milliseconds since the unix epoch.

**Details**

Expand All @@ -169,18 +169,19 @@ It runs a maximum of [`option: loopLimit`] times after which it assumes there is

## async method: Clock.runToLast
* since: v1.45
- returns: <[int]> Fake milliseconds since the unix epoch.
- returns: <[int]>

This takes note of the last scheduled timer when it is run, and advances the clock to that time firing callbacks as necessary.
If new timers are added while it is executing they will be run only if they would occur before this time.
This is useful when you want to run a test to completion, but the test recursively sets timers that would cause runAll to trigger an infinite loop warning.
Returns fake milliseconds since the unix epoch.


## async method: Clock.tick
* since: v1.45
- returns: <[int]> Fake milliseconds since the unix epoch.
- returns: <[int]>

Advance the clock, firing callbacks if necessary. Returns fake milliseconds since the unix epoch.
Advance the clock, firing callbacks if necessary. Returns fake milliseconds since the unix epoch. Returns fake milliseconds since the unix epoch.

**Usage**

Expand Down
15 changes: 8 additions & 7 deletions packages/playwright-core/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17291,9 +17291,8 @@ export interface Clock {
}): Promise<void>;

/**
* Advance the clock by jumping forward in time, firing callbacks at most once. Returns fake milliseconds since the
* unix epoch. This can be used to simulate the JS engine (such as a browser) being put to sleep and resumed later,
* skipping intermediary timers.
* Advance the clock by jumping forward in time, firing callbacks at most once. This can be used to simulate the JS
* engine (such as a browser) being put to sleep and resumed later, skipping intermediary timers.
*
* **Usage**
*
Expand All @@ -17308,7 +17307,8 @@ export interface Clock {
jump(time: number|string): Promise<void>;

/**
* Advances the clock to the the moment of the first scheduled timer, firing it.
* Advances the clock to the the moment of the first scheduled timer, firing it. Returns fake milliseconds since the
* unix epoch.
*
* **Usage**
*
Expand All @@ -17321,7 +17321,7 @@ export interface Clock {

/**
* Runs all pending timers until there are none remaining. If new timers are added while it is executing they will be
* run as well.
* run as well. Returns fake milliseconds since the unix epoch.
*
* **Details**
*
Expand All @@ -17335,12 +17335,13 @@ export interface Clock {
* This takes note of the last scheduled timer when it is run, and advances the clock to that time firing callbacks as
* necessary. If new timers are added while it is executing they will be run only if they would occur before this
* time. This is useful when you want to run a test to completion, but the test recursively sets timers that would
* cause runAll to trigger an infinite loop warning.
* cause runAll to trigger an infinite loop warning. Returns fake milliseconds since the unix epoch.
*/
runToLast(): Promise<number>;

/**
* Advance the clock, firing callbacks if necessary. Returns fake milliseconds since the unix epoch.
* Advance the clock, firing callbacks if necessary. Returns fake milliseconds since the unix epoch. Returns fake
* milliseconds since the unix epoch.
*
* **Usage**
*
Expand Down

0 comments on commit 8d0def1

Please sign in to comment.