-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Sasha Koss <koss@nocorp.me>
- Loading branch information
1 parent
8271303
commit 3611e63
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import assert from "assert"; | ||
import { describe, it } from "vitest"; | ||
import { constructFrom } from "."; | ||
|
||
describe("constructFrom", () => { | ||
it("should create a new Date instance using the constructor from the reference date", () => { | ||
const referenceDate = new Date("2023-10-25T12:00:00"); | ||
const value = new Date("2023-10-26T12:00:00"); | ||
|
||
const result = constructFrom(referenceDate, value); | ||
|
||
assert.ok(result instanceof Date); | ||
assert.deepStrictEqual(result, value); | ||
assert.strictEqual(result.constructor, referenceDate.constructor); | ||
}); | ||
|
||
it("should create a new Date instance using a number as the reference date", () => { | ||
const referenceDate = 1635158400000; // October 25, 2023 | ||
const value = new Date("2023-10-26T12:00:00"); | ||
|
||
const result = constructFrom(referenceDate, value); | ||
|
||
assert.ok(result instanceof Date); | ||
assert.deepStrictEqual(result, value); | ||
}); | ||
|
||
it("should create a new custom Date instance using the constructor from the reference date", () => { | ||
class CustomDate extends Date {} | ||
const referenceDate = new CustomDate("2023-10-25T12:00:00"); | ||
const value = new CustomDate("2023-10-26T12:00:00"); | ||
|
||
const result = constructFrom(referenceDate, value); | ||
|
||
assert.ok(result instanceof CustomDate); | ||
assert.deepStrictEqual(result, value); | ||
assert.strictEqual(result.constructor, referenceDate.constructor); | ||
}); | ||
|
||
it("should create a new Date instance using numbers as both referenceDate and value", () => { | ||
const referenceDate = 1635158400000; // October 25, 2023 | ||
const value = 1635244800000; // October 26, 2023 | ||
|
||
const result = constructFrom(referenceDate, value); | ||
|
||
assert.ok(result instanceof Date); | ||
assert.deepStrictEqual(result.getTime(), value); | ||
}); | ||
}); |