Skip to content

Commit 3e6793a

Browse files
committed
Remove yet more unnecessary
1 parent 507257d commit 3e6793a

1 file changed

Lines changed: 5 additions & 19 deletions

File tree

src/index.ts

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as assert from "assert";
22
import * as util from "util";
3-
import type { Clock } from "@sinonjs/fake-timers";
43

54
// Grab the setTimeout from global before jest overwrites it with useFakeTimers
65
const setTimeoutBypassingFakes = global.setTimeout;
@@ -127,18 +126,15 @@ export function setupFakeTimers() {
127126
)}'`,
128127
);
129128

130-
const clock = (Date as any).clock;
131-
assertSinonJsClock(clock);
132-
133-
if (targetTimestamp < clock.now) {
134-
clock.setSystemTime(targetTimestamp);
129+
if (targetTimestamp < Date.now()) {
130+
jest.setSystemTime(targetTimestamp);
135131
} else {
136-
while (clock.now + increment < targetTimestamp) {
132+
while (Date.now() + increment < targetTimestamp) {
137133
jest.advanceTimersByTime(increment);
138134
await aFewRunLoops();
139135
}
140-
if (clock.now < targetTimestamp) {
141-
jest.advanceTimersByTime(targetTimestamp - clock.now);
136+
if (Date.now() < targetTimestamp) {
137+
jest.advanceTimersByTime(targetTimestamp - Date.now());
142138
await aFewRunLoops();
143139
}
144140
}
@@ -149,16 +145,6 @@ export function setupFakeTimers() {
149145
return { setTime, realNow };
150146
}
151147

152-
function assertSinonJsClock(clock: any): asserts clock is Clock {
153-
if (
154-
!clock ||
155-
typeof clock.now !== "number" ||
156-
typeof clock.setSystemTime !== "function"
157-
) {
158-
throw new Error(`Expected sinonjs clock!`);
159-
}
160-
}
161-
162148
/** One second in milliseconds */
163149
export const SECOND = 1000;
164150
/** One minute in milliseconds */

0 commit comments

Comments
 (0)