mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
BREAKING(testing): disable multiple FakeTime
creations (#5130)
This commit is contained in:
parent
a4d4e51cfa
commit
3204a708a5
@ -313,7 +313,7 @@ export class FakeTime {
|
||||
start?: number | string | Date | null,
|
||||
options?: FakeTimeOptions,
|
||||
) {
|
||||
if (time) time.restore();
|
||||
if (time) throw new TimeError("The time is already faked");
|
||||
initializedAt = _internals.Date.now();
|
||||
startedAt = start instanceof Date
|
||||
? start.valueOf()
|
||||
|
@ -7,6 +7,7 @@ import {
|
||||
assertNotEquals,
|
||||
assertRejects,
|
||||
assertStrictEquals,
|
||||
assertThrows,
|
||||
} from "@std/assert";
|
||||
import { FakeTime, TimeError } from "./time.ts";
|
||||
import { _internals } from "./_time.ts";
|
||||
@ -638,3 +639,8 @@ Deno.test("Date from FakeTime is structured cloneable", () => {
|
||||
assert(date instanceof Date);
|
||||
assert(cloned instanceof Date_);
|
||||
});
|
||||
|
||||
Deno.test("new FakeTime() throws if the time is already faked", () => {
|
||||
using _time = new FakeTime();
|
||||
assertThrows(() => new FakeTime());
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user