From 653148525135ff0ed2aec1fe7ffe5862c4064026 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Thu, 8 Jul 2021 22:31:39 +0100 Subject: [PATCH] LibJS/Tests: Add tests for Temporal.Instant() constructor --- .../builtins/Temporal/Instant/Instant.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Userland/Libraries/LibJS/Tests/builtins/Temporal/Instant/Instant.js diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/Instant/Instant.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/Instant/Instant.js new file mode 100644 index 0000000000..e4b1635983 --- /dev/null +++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/Instant/Instant.js @@ -0,0 +1,30 @@ +describe("errors", () => { + test("called without new", () => { + expect(() => { + Temporal.Instant(); + }).toThrowWithMessage(TypeError, "Temporal.Instant constructor must be called with 'new'"); + }); + + test("argument must be coercible to bigint", () => { + expect(() => { + new Temporal.Instant(123); + }).toThrowWithMessage(TypeError, "Cannot convert number to BigInt"); + expect(() => { + new Temporal.Instant("foo"); + }).toThrowWithMessage(SyntaxError, "Invalid value for BigInt: foo"); + }); +}); + +describe("normal behavior", () => { + test("length is 1", () => { + expect(Temporal.Instant).toHaveLength(1); + }); + + test("basic functionality", () => { + const instant = new Temporal.Instant(123n); + expect(instant.epochNanoseconds).toBe(123n); + expect(typeof instant).toBe("object"); + expect(instant).toBeInstanceOf(Temporal.Instant); + expect(Object.getPrototypeOf(instant)).toBe(Temporal.Instant.prototype); + }); +});