1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 05:44:59 +00:00
serenity/Userland/Libraries/LibJS/Tests/builtins/Temporal/Instant/Instant.fromEpochMicroseconds.js
Linus Groh a8ba2f4b21 LibJS/Tests: Fix bad copy and paste that crept into a lot of tests
The top-level function should have been `describe()``, but instead it's
been nested `test()`s.
2021-08-07 12:10:34 +01:00

51 lines
2.1 KiB
JavaScript

describe("correct behavior", () => {
test("length is 1", () => {
expect(Temporal.Instant.fromEpochMicroseconds).toHaveLength(1);
});
test("basic functionality", () => {
expect(Temporal.Instant.fromEpochMicroseconds(0n).epochMicroseconds).toBe(0n);
expect(Temporal.Instant.fromEpochMicroseconds(1n).epochMicroseconds).toBe(1n);
expect(Temporal.Instant.fromEpochMicroseconds(999_999_999n).epochMicroseconds).toBe(
999_999_999n
);
expect(
Temporal.Instant.fromEpochMicroseconds(8_640_000_000_000_000_000n).epochMicroseconds
).toBe(8_640_000_000_000_000_000n);
expect(Temporal.Instant.fromEpochMicroseconds(-0n).epochMicroseconds).toBe(0n);
expect(Temporal.Instant.fromEpochMicroseconds(-1n).epochMicroseconds).toBe(-1n);
expect(Temporal.Instant.fromEpochMicroseconds(-999_999_999n).epochMicroseconds).toBe(
-999_999_999n
);
expect(
Temporal.Instant.fromEpochMicroseconds(-8_640_000_000_000_000_000n).epochMicroseconds
).toBe(-8_640_000_000_000_000_000n);
});
});
describe("errors", () => {
test("argument must be coercible to BigInt", () => {
expect(() => {
Temporal.Instant.fromEpochMicroseconds(123);
}).toThrowWithMessage(TypeError, "Cannot convert number to BigInt");
expect(() => {
Temporal.Instant.fromEpochMicroseconds("foo");
}).toThrowWithMessage(SyntaxError, "Invalid value for BigInt: foo");
});
test("out-of-range epoch microseconds value", () => {
expect(() => {
Temporal.Instant.fromEpochMicroseconds(8_640_000_000_000_000_001n);
}).toThrowWithMessage(
RangeError,
"Invalid epoch nanoseconds value, must be in range -86400 * 10^17 to 86400 * 10^17"
);
expect(() => {
Temporal.Instant.fromEpochMicroseconds(-8_640_000_000_000_000_001n);
}).toThrowWithMessage(
RangeError,
"Invalid epoch nanoseconds value, must be in range -86400 * 10^17 to 86400 * 10^17"
);
});
});