Tests for Temporal PR #2574

Edits Temporal tests to account for changes in
https://github.com/tc39/proposal-temporal/pull/2574.

This PR stops coercing non-string primitive inputs to strings
in Temporal methods, to avoid cases where numbers
are coerced to syntactically valid but often unexpected
string results.
This commit is contained in:
Justin Grant 2023-06-10 10:17:39 -07:00 committed by Philip Chimento
parent 016e4bf8e8
commit 60e475248d
321 changed files with 2059 additions and 1745 deletions

View File

@ -0,0 +1,30 @@
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar
description: RangeError thrown when constructor invoked with the wrong type
features: [Temporal]
---*/
const tests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[19761118, "number that would convert to a valid ISO string in other contexts"],
[1n, "bigint"],
[Symbol(), "symbol"],
[{}, "object not implementing any protocol"],
[new Temporal.Calendar("iso8601"), "calendar instance"],
[new Temporal.TimeZone("UTC"), "time zone instance"],
[Temporal.ZonedDateTime.from("2020-01-01T00:00Z[UTC]"), "ZonedDateTime instance"],
];
for (const [arg, description] of tests) {
assert.throws(
typeof (arg) === "string" ? RangeError : TypeError,
() => new Temporal.Calendar(arg),
`${description} is not accepted by this constructor`
);
}

View File

@ -3,25 +3,21 @@
/*--- /*---
esid: sec-temporal.calendar.from esid: sec-temporal.calendar.from
description: A number is converted to a string, then to Temporal.Calendar description: A number is not allowed to be a calendar
features: [Temporal] features: [Temporal]
---*/ ---*/
const arg = 19761118;
const result = Temporal.Calendar.from(arg);
assert.sameValue(result.id, "iso8601", "19761118 is a valid ISO string for Calendar");
const numbers = [ const numbers = [
1, 1,
-19761118, -19761118,
19761118,
1234567890, 1234567890,
]; ];
for (const arg of numbers) { for (const arg of numbers) {
assert.throws( assert.throws(
RangeError, TypeError,
() => Temporal.Calendar.from(arg), () => Temporal.Calendar.from(arg),
`Number ${arg} does not convert to a valid ISO string for Calendar` "A number is not a valid ISO string for Calendar"
); );
} }

View File

@ -9,7 +9,7 @@ description: >
features: [BigInt, Symbol, Temporal] features: [BigInt, Symbol, Temporal]
---*/ ---*/
const rangeErrorTests = [ const primitiveTests = [
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
["", "empty string"], ["", "empty string"],
@ -17,8 +17,12 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [arg, description] of rangeErrorTests) { for (const [arg, description] of primitiveTests) {
assert.throws(RangeError, () => Temporal.Calendar.from(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof arg === 'string' ? RangeError : TypeError,
() => Temporal.Calendar.from(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -7,5 +7,5 @@ description: RangeError thrown when constructor invoked with no argument
features: [Temporal] features: [Temporal]
---*/ ---*/
assert.throws(RangeError, () => new Temporal.Calendar()); assert.throws(TypeError, () => new Temporal.Calendar());
assert.throws(RangeError, () => new Temporal.Calendar(undefined)); assert.throws(TypeError, () => new Temporal.Calendar(undefined));

View File

@ -3,28 +3,23 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.dateadd esid: sec-temporal.calendar.prototype.dateadd
description: A number is converted to a string, then to Temporal.PlainDate description: A number cannot be used in place of a Temporal.PlainDate
includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const arg = 19761118;
const result = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(result, 1976, 11, "M11", 18, "19761118 is a valid ISO string for PlainDate");
const numbers = [ const numbers = [
1, 1,
19761118,
-19761118, -19761118,
1234567890, 1234567890,
]; ];
for (const arg of numbers) { for (const arg of numbers) {
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.dateAdd(arg, new Temporal.Duration()), () => instance.dateAdd(arg, new Temporal.Duration()),
`Number ${arg} does not convert to a valid ISO string for PlainDate` 'Numbers cannot be used in place of an ISO string for PlainDate'
); );
} }

View File

@ -3,30 +3,23 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.dateadd esid: sec-temporal.calendar.prototype.dateadd
description: A number as calendar in a property bag is converted to a string, then to a calendar description: A number as calendar in a property bag is not accepted
includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.PlainDate(1976, 11, 18);
const calendar = 19970327;
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(result, 1976, 11, "M11", 18, "19970327 is a valid ISO string for calendar");
const numbers = [ const numbers = [
1, 1,
19970327,
-19970327, -19970327,
1234567890, 1234567890,
]; ];
for (const calendar of numbers) { for (const calendar of numbers) {
const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.dateAdd(arg, new Temporal.Duration()), () => instance.dateAdd(arg, new Temporal.Duration()),
`Number ${calendar} does not convert to a valid ISO string for calendar` "Numbers cannot be used as a calendar"
); );
} }

View File

@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal]
const timeZone = new Temporal.TimeZone("UTC"); const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
["", "empty string"], ["", "empty string"],
@ -20,9 +20,13 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [calendar, description] of rangeErrorTests) { for (const [calendar, description] of primitiveTests) {
const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.dateAdd(arg, new Temporal.Duration()), `${description} does not convert to a valid ISO string`); assert.throws(
typeof calendar === 'string' ? RangeError : TypeError,
() => instance.dateAdd(arg, new Temporal.Duration()),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal]
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[undefined, "undefined"], [undefined, "undefined"],
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
@ -20,8 +20,12 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [arg, description] of rangeErrorTests) { for (const [arg, description] of primitiveTests) {
assert.throws(RangeError, () => instance.dateAdd(arg, new Temporal.Duration()), `${description} does not convert to a valid ISO string`); assert.throws(
typeof arg === 'string' ? RangeError : TypeError,
() => instance.dateAdd(arg, new Temporal.Duration()),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -3,35 +3,28 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.dateuntil esid: sec-temporal.calendar.prototype.dateuntil
description: A number is converted to a string, then to Temporal.PlainDate description: A number cannot be used in place of a Temporal.PlainDate
includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const arg = 19761118;
const result1 = instance.dateUntil(arg, new Temporal.PlainDate(1976, 11, 19));
TemporalHelpers.assertDuration(result1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "19761118 is a valid ISO string for PlainDate (first argument)");
const result2 = instance.dateUntil(new Temporal.PlainDate(1976, 11, 19), arg);
TemporalHelpers.assertDuration(result2, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "19761118 is a valid ISO string for PlainDate (second argument)");
const numbers = [ const numbers = [
1, 1,
19761118,
-19761118, -19761118,
1234567890, 1234567890,
]; ];
for (const arg of numbers) { for (const arg of numbers) {
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 18)), () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 18)),
`Number ${arg} does not convert to a valid ISO string for PlainDate (first argument)` "A number is not a valid ISO string for PlainDate (first argument)"
); );
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.dateUntil(new Temporal.PlainDate(1977, 11, 18), arg), () => instance.dateUntil(new Temporal.PlainDate(1977, 11, 18), arg),
`Number ${arg} does not convert to a valid ISO string for PlainDate (second argument)` "A number is not a valid ISO string for PlainDate (second argument)"
); );
} }

View File

@ -3,23 +3,15 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.dateuntil esid: sec-temporal.calendar.prototype.dateuntil
description: A number as calendar in a property bag is converted to a string, then to a calendar description: A number as calendar in a property bag is not accepted
includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const calendar = 19970327;
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.dateUntil(arg, new Temporal.PlainDate(1976, 11, 19));
TemporalHelpers.assertDuration(result1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar (first argument)");
const result2 = instance.dateUntil(new Temporal.PlainDate(1976, 11, 19), arg);
TemporalHelpers.assertDuration(result2, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar (second argument)");
const numbers = [ const numbers = [
1, 1,
19970327,
-19970327, -19970327,
1234567890, 1234567890,
]; ];
@ -27,13 +19,13 @@ const numbers = [
for (const calendar of numbers) { for (const calendar of numbers) {
const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)), () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)),
`Number ${calendar} does not convert to a valid ISO string for calendar (first argument)` "A number is not a valid ISO string for calendar (first argument)"
); );
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg), () => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg),
`Number ${calendar} does not convert to a valid ISO string for calendar (second argument)` "A number is not a valid ISO string for calendar (second argument)"
); );
} }

View File

@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal]
const timeZone = new Temporal.TimeZone("UTC"); const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
["", "empty string"], ["", "empty string"],
@ -20,10 +20,18 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [calendar, description] of rangeErrorTests) { for (const [calendar, description] of primitiveTests) {
const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)), `${description} does not convert to a valid ISO string (first argument)`); assert.throws(
assert.throws(RangeError, () => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg), `${description} does not convert to a valid ISO string (second argument)`); typeof calendar === "string" ? RangeError : TypeError,
() => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)),
`${description} does not convert to a valid ISO string (first argument)`
);
assert.throws(
typeof calendar === "string" ? RangeError : TypeError,
() => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg),
`${description} does not convert to a valid ISO string (second argument)`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal]
const timeZone = new Temporal.TimeZone("UTC"); const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[undefined, "undefined"], [undefined, "undefined"],
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
@ -21,9 +21,17 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [arg, description] of rangeErrorTests) { for (const [arg, description] of primitiveTests) {
assert.throws(RangeError, () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)), `${description} does not convert to a valid ISO string (first argument)`); assert.throws(
assert.throws(RangeError, () => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg), `${description} does not convert to a valid ISO string (first argument)`); typeof arg === 'string' ? RangeError : TypeError,
() => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)),
`${description} does not convert to a valid ISO string (first argument)`
);
assert.throws(
typeof arg === 'string' ? RangeError : TypeError,
() => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg),
`${description} does not convert to a valid ISO string (second argument)`
);
} }
const typeErrorTests = [ const typeErrorTests = [
@ -34,6 +42,6 @@ const typeErrorTests = [
]; ];
for (const [arg, description] of typeErrorTests) { for (const [arg, description] of typeErrorTests) {
assert.throws(TypeError, () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)), `${description} is not a valid property bag and does not convert to a string (second argument)`); assert.throws(TypeError, () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)), `${description} is not a valid property bag and does not convert to a string (first argument)`);
assert.throws(TypeError, () => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg), `${description} is not a valid property bag and does not convert to a string (second argument)`); assert.throws(TypeError, () => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg), `${description} is not a valid property bag and does not convert to a string (second argument)`);
} }

View File

@ -3,27 +3,23 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.day esid: sec-temporal.calendar.prototype.day
description: A number is converted to a string, then to Temporal.PlainDate description: A number cannot be used in place of a Temporal.PlainDate
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const arg = 19761118;
const result = instance.day(arg);
assert.sameValue(result, 18, "19761118 is a valid ISO string for PlainDate");
const numbers = [ const numbers = [
1, 1,
19761118,
-19761118, -19761118,
1234567890, 1234567890,
]; ];
for (const arg of numbers) { for (const arg of numbers) {
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.day(arg), () => instance.day(arg),
`Number ${arg} does not convert to a valid ISO string for PlainDate` 'Numbers cannot be used in place of an ISO string for PlainDate'
); );
} }

View File

@ -3,20 +3,15 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.day esid: sec-temporal.calendar.prototype.day
description: A number as calendar in a property bag is converted to a string, then to a calendar description: A number as calendar in a property bag is not accepted
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const calendar = 19970327;
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.day(arg);
assert.sameValue(result, 18, "19970327 is a valid ISO string for calendar");
const numbers = [ const numbers = [
1, 1,
19970327,
-19970327, -19970327,
1234567890, 1234567890,
]; ];
@ -24,8 +19,8 @@ const numbers = [
for (const calendar of numbers) { for (const calendar of numbers) {
const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.day(arg), () => instance.day(arg),
`Number ${calendar} does not convert to a valid ISO string for calendar` "Numbers cannot be used as a calendar"
); );
} }

View File

@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal]
const timeZone = new Temporal.TimeZone("UTC"); const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
["", "empty string"], ["", "empty string"],
@ -20,9 +20,13 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [calendar, description] of rangeErrorTests) { for (const [calendar, description] of primitiveTests) {
const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.day(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof calendar === 'string' ? RangeError : TypeError,
() => instance.day(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal]
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[undefined, "undefined"], [undefined, "undefined"],
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
@ -20,8 +20,12 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [arg, description] of rangeErrorTests) { for (const [arg, description] of primitiveTests) {
assert.throws(RangeError, () => instance.day(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof arg === 'string' ? RangeError : TypeError,
() => instance.day(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -3,27 +3,23 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.dayofweek esid: sec-temporal.calendar.prototype.dayofweek
description: A number is converted to a string, then to Temporal.PlainDate description: A number cannot be used in place of a Temporal.PlainDate
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const arg = 19761118;
const result = instance.dayOfWeek(arg);
assert.sameValue(result, 4, "19761118 is a valid ISO string for PlainDate");
const numbers = [ const numbers = [
1, 1,
19761118,
-19761118, -19761118,
1234567890, 1234567890,
]; ];
for (const arg of numbers) { for (const arg of numbers) {
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.dayOfWeek(arg), () => instance.dayOfWeek(arg),
`Number ${arg} does not convert to a valid ISO string for PlainDate` 'Numbers cannot be used in place of an ISO string for PlainDate'
); );
} }

View File

@ -3,20 +3,15 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.dayofweek esid: sec-temporal.calendar.prototype.dayofweek
description: A number as calendar in a property bag is converted to a string, then to a calendar description: A number as calendar in a property bag is not accepted
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const calendar = 19970327;
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.dayOfWeek(arg);
assert.sameValue(result, 4, "19970327 is a valid ISO string for calendar");
const numbers = [ const numbers = [
1, 1,
19970327,
-19970327, -19970327,
1234567890, 1234567890,
]; ];
@ -24,8 +19,8 @@ const numbers = [
for (const calendar of numbers) { for (const calendar of numbers) {
const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.dayOfWeek(arg), () => instance.dayOfWeek(arg),
`Number ${calendar} does not convert to a valid ISO string for calendar` "Numbers cannot be used as a calendar"
); );
} }

View File

@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal]
const timeZone = new Temporal.TimeZone("UTC"); const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
["", "empty string"], ["", "empty string"],
@ -20,9 +20,13 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [calendar, description] of rangeErrorTests) { for (const [calendar, description] of primitiveTests) {
const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.dayOfWeek(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof calendar === 'string' ? RangeError : TypeError,
() => instance.dayOfWeek(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal]
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[undefined, "undefined"], [undefined, "undefined"],
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
@ -20,8 +20,12 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [arg, description] of rangeErrorTests) { for (const [arg, description] of primitiveTests) {
assert.throws(RangeError, () => instance.dayOfWeek(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof arg === 'string' ? RangeError : TypeError,
() => instance.dayOfWeek(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -3,27 +3,23 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.dayofyear esid: sec-temporal.calendar.prototype.dayofyear
description: A number is converted to a string, then to Temporal.PlainDate description: A number cannot be used in place of a Temporal.PlainDate
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const arg = 19761118;
const result = instance.dayOfYear(arg);
assert.sameValue(result, 323, "19761118 is a valid ISO string for PlainDate");
const numbers = [ const numbers = [
1, 1,
19761118,
-19761118, -19761118,
1234567890, 1234567890,
]; ];
for (const arg of numbers) { for (const arg of numbers) {
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.dayOfYear(arg), () => instance.dayOfYear(arg),
`Number ${arg} does not convert to a valid ISO string for PlainDate` 'Numbers cannot be used in place of an ISO string for PlainDate'
); );
} }

View File

@ -3,20 +3,15 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.dayofyear esid: sec-temporal.calendar.prototype.dayofyear
description: A number as calendar in a property bag is converted to a string, then to a calendar description: A number as calendar in a property bag is not accepted
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const calendar = 19970327;
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.dayOfYear(arg);
assert.sameValue(result, 323, "19970327 is a valid ISO string for calendar");
const numbers = [ const numbers = [
1, 1,
19970327,
-19970327, -19970327,
1234567890, 1234567890,
]; ];
@ -24,8 +19,8 @@ const numbers = [
for (const calendar of numbers) { for (const calendar of numbers) {
const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.dayOfYear(arg), () => instance.dayOfYear(arg),
`Number ${calendar} does not convert to a valid ISO string for calendar` "Numbers cannot be used as a calendar"
); );
} }

View File

@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal]
const timeZone = new Temporal.TimeZone("UTC"); const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
["", "empty string"], ["", "empty string"],
@ -20,9 +20,13 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [calendar, description] of rangeErrorTests) { for (const [calendar, description] of primitiveTests) {
const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.dayOfYear(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof calendar === 'string' ? RangeError : TypeError,
() => instance.dayOfYear(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal]
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[undefined, "undefined"], [undefined, "undefined"],
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
@ -20,8 +20,12 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [arg, description] of rangeErrorTests) { for (const [arg, description] of primitiveTests) {
assert.throws(RangeError, () => instance.dayOfYear(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof arg === 'string' ? RangeError : TypeError,
() => instance.dayOfYear(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -3,27 +3,23 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.daysinmonth esid: sec-temporal.calendar.prototype.daysinmonth
description: A number is converted to a string, then to Temporal.PlainDate description: A number cannot be used in place of a Temporal.PlainDate
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const arg = 19761118;
const result = instance.daysInMonth(arg);
assert.sameValue(result, 30, "19761118 is a valid ISO string for PlainDate");
const numbers = [ const numbers = [
1, 1,
19761118,
-19761118, -19761118,
1234567890, 1234567890,
]; ];
for (const arg of numbers) { for (const arg of numbers) {
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.daysInMonth(arg), () => instance.daysInMonth(arg),
`Number ${arg} does not convert to a valid ISO string for PlainDate` 'Numbers cannot be used in place of an ISO string for PlainDate'
); );
} }

View File

@ -3,20 +3,15 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.daysinmonth esid: sec-temporal.calendar.prototype.daysinmonth
description: A number as calendar in a property bag is converted to a string, then to a calendar description: A number as calendar in a property bag is not accepted
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const calendar = 19970327;
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.daysInMonth(arg);
assert.sameValue(result, 30, "19970327 is a valid ISO string for calendar");
const numbers = [ const numbers = [
1, 1,
19970327,
-19970327, -19970327,
1234567890, 1234567890,
]; ];
@ -24,8 +19,8 @@ const numbers = [
for (const calendar of numbers) { for (const calendar of numbers) {
const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.daysInMonth(arg), () => instance.daysInMonth(arg),
`Number ${calendar} does not convert to a valid ISO string for calendar` "Numbers cannot be used as a calendar"
); );
} }

View File

@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal]
const timeZone = new Temporal.TimeZone("UTC"); const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
["", "empty string"], ["", "empty string"],
@ -20,9 +20,13 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [calendar, description] of rangeErrorTests) { for (const [calendar, description] of primitiveTests) {
const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.daysInMonth(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof calendar === 'string' ? RangeError : TypeError,
() => instance.daysInMonth(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal]
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[undefined, "undefined"], [undefined, "undefined"],
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
@ -20,8 +20,12 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [arg, description] of rangeErrorTests) { for (const [arg, description] of primitiveTests) {
assert.throws(RangeError, () => instance.daysInMonth(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof arg === 'string' ? RangeError : TypeError,
() => instance.daysInMonth(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -3,27 +3,23 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.daysinweek esid: sec-temporal.calendar.prototype.daysinweek
description: A number is converted to a string, then to Temporal.PlainDate description: A number cannot be used in place of a Temporal.PlainDate
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const arg = 19761118;
const result = instance.daysInWeek(arg);
assert.sameValue(result, 7, "19761118 is a valid ISO string for PlainDate");
const numbers = [ const numbers = [
1, 1,
19761118,
-19761118, -19761118,
1234567890, 1234567890,
]; ];
for (const arg of numbers) { for (const arg of numbers) {
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.daysInWeek(arg), () => instance.daysInWeek(arg),
`Number ${arg} does not convert to a valid ISO string for PlainDate` 'Numbers cannot be used in place of an ISO string for PlainDate'
); );
} }

View File

@ -3,20 +3,15 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.daysinweek esid: sec-temporal.calendar.prototype.daysinweek
description: A number as calendar in a property bag is converted to a string, then to a calendar description: A number as calendar in a property bag is not accepted
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const calendar = 19970327;
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.daysInWeek(arg);
assert.sameValue(result, 7, "19970327 is a valid ISO string for calendar");
const numbers = [ const numbers = [
1, 1,
19970327,
-19970327, -19970327,
1234567890, 1234567890,
]; ];
@ -24,8 +19,8 @@ const numbers = [
for (const calendar of numbers) { for (const calendar of numbers) {
const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.daysInWeek(arg), () => instance.daysInWeek(arg),
`Number ${calendar} does not convert to a valid ISO string for calendar` "Numbers cannot be used as a calendar"
); );
} }

View File

@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal]
const timeZone = new Temporal.TimeZone("UTC"); const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
["", "empty string"], ["", "empty string"],
@ -20,9 +20,13 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [calendar, description] of rangeErrorTests) { for (const [calendar, description] of primitiveTests) {
const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.daysInWeek(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof calendar === 'string' ? RangeError : TypeError,
() => instance.daysInWeek(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal]
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[undefined, "undefined"], [undefined, "undefined"],
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
@ -20,8 +20,12 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [arg, description] of rangeErrorTests) { for (const [arg, description] of primitiveTests) {
assert.throws(RangeError, () => instance.daysInWeek(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof arg === 'string' ? RangeError : TypeError,
() => instance.daysInWeek(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -3,27 +3,23 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.daysinyear esid: sec-temporal.calendar.prototype.daysinyear
description: A number is converted to a string, then to Temporal.PlainDate description: A number cannot be used in place of a Temporal.PlainDate
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const arg = 19761118;
const result = instance.daysInYear(arg);
assert.sameValue(result, 366, "19761118 is a valid ISO string for PlainDate");
const numbers = [ const numbers = [
1, 1,
19761118,
-19761118, -19761118,
1234567890, 1234567890,
]; ];
for (const arg of numbers) { for (const arg of numbers) {
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.daysInYear(arg), () => instance.daysInYear(arg),
`Number ${arg} does not convert to a valid ISO string for PlainDate` 'Numbers cannot be used in place of an ISO string for PlainDate'
); );
} }

View File

@ -3,20 +3,15 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.daysinyear esid: sec-temporal.calendar.prototype.daysinyear
description: A number as calendar in a property bag is converted to a string, then to a calendar description: A number as calendar in a property bag is not accepted
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const calendar = 19970327;
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.daysInYear(arg);
assert.sameValue(result, 366, "19970327 is a valid ISO string for calendar");
const numbers = [ const numbers = [
1, 1,
19970327,
-19970327, -19970327,
1234567890, 1234567890,
]; ];
@ -24,8 +19,8 @@ const numbers = [
for (const calendar of numbers) { for (const calendar of numbers) {
const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.daysInYear(arg), () => instance.daysInYear(arg),
`Number ${calendar} does not convert to a valid ISO string for calendar` "Numbers cannot be used as a calendar"
); );
} }

View File

@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal]
const timeZone = new Temporal.TimeZone("UTC"); const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
["", "empty string"], ["", "empty string"],
@ -20,9 +20,13 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [calendar, description] of rangeErrorTests) { for (const [calendar, description] of primitiveTests) {
const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.daysInYear(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof calendar === 'string' ? RangeError : TypeError,
() => instance.daysInYear(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal]
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[undefined, "undefined"], [undefined, "undefined"],
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
@ -20,8 +20,12 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [arg, description] of rangeErrorTests) { for (const [arg, description] of primitiveTests) {
assert.throws(RangeError, () => instance.daysInYear(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof arg === 'string' ? RangeError : TypeError,
() => instance.daysInYear(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -3,27 +3,23 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.inleapyear esid: sec-temporal.calendar.prototype.inleapyear
description: A number is converted to a string, then to Temporal.PlainDate description: A number cannot be used in place of a Temporal.PlainDate
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const arg = 19761118;
const result = instance.inLeapYear(arg);
assert.sameValue(result, true, "19761118 is a valid ISO string for PlainDate");
const numbers = [ const numbers = [
1, 1,
19761118,
-19761118, -19761118,
1234567890, 1234567890,
]; ];
for (const arg of numbers) { for (const arg of numbers) {
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.inLeapYear(arg), () => instance.inLeapYear(arg),
`Number ${arg} does not convert to a valid ISO string for PlainDate` 'Numbers cannot be used in place of an ISO string for PlainDate'
); );
} }

View File

@ -3,20 +3,15 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.inleapyear esid: sec-temporal.calendar.prototype.inleapyear
description: A number as calendar in a property bag is converted to a string, then to a calendar description: A number as calendar in a property bag is not accepted
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const calendar = 19970327;
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.inLeapYear(arg);
assert.sameValue(result, true, "19970327 is a valid ISO string for calendar");
const numbers = [ const numbers = [
1, 1,
19970327,
-19970327, -19970327,
1234567890, 1234567890,
]; ];
@ -24,8 +19,8 @@ const numbers = [
for (const calendar of numbers) { for (const calendar of numbers) {
const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.inLeapYear(arg), () => instance.inLeapYear(arg),
`Number ${calendar} does not convert to a valid ISO string for calendar` "Numbers cannot be used as a calendar"
); );
} }

View File

@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal]
const timeZone = new Temporal.TimeZone("UTC"); const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
["", "empty string"], ["", "empty string"],
@ -20,9 +20,13 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [calendar, description] of rangeErrorTests) { for (const [calendar, description] of primitiveTests) {
const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.inLeapYear(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof calendar === 'string' ? RangeError : TypeError,
() => instance.inLeapYear(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal]
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[undefined, "undefined"], [undefined, "undefined"],
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
@ -20,8 +20,12 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [arg, description] of rangeErrorTests) { for (const [arg, description] of primitiveTests) {
assert.throws(RangeError, () => instance.inLeapYear(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof arg === 'string' ? RangeError : TypeError,
() => instance.inLeapYear(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -3,27 +3,23 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.month esid: sec-temporal.calendar.prototype.month
description: A number is converted to a string, then to Temporal.PlainDate description: A number cannot be used in place of a Temporal.PlainDate
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const arg = 19761118;
const result = instance.month(arg);
assert.sameValue(result, 11, "19761118 is a valid ISO string for PlainDate");
const numbers = [ const numbers = [
1, 1,
19761118,
-19761118, -19761118,
1234567890, 1234567890,
]; ];
for (const arg of numbers) { for (const arg of numbers) {
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.month(arg), () => instance.month(arg),
`Number ${arg} does not convert to a valid ISO string for PlainDate` 'Numbers cannot be used in place of an ISO string for PlainDate'
); );
} }

View File

@ -3,20 +3,15 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.month esid: sec-temporal.calendar.prototype.month
description: A number as calendar in a property bag is converted to a string, then to a calendar description: A number as calendar in a property bag is not accepted
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const calendar = 19970327;
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.month(arg);
assert.sameValue(result, 11, "19970327 is a valid ISO string for calendar");
const numbers = [ const numbers = [
1, 1,
19970327,
-19970327, -19970327,
1234567890, 1234567890,
]; ];
@ -24,8 +19,8 @@ const numbers = [
for (const calendar of numbers) { for (const calendar of numbers) {
const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.month(arg), () => instance.month(arg),
`Number ${calendar} does not convert to a valid ISO string for calendar` "Numbers cannot be used as a calendar"
); );
} }

View File

@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal]
const timeZone = new Temporal.TimeZone("UTC"); const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
["", "empty string"], ["", "empty string"],
@ -20,9 +20,13 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [calendar, description] of rangeErrorTests) { for (const [calendar, description] of primitiveTests) {
const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.month(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof calendar === 'string' ? RangeError : TypeError,
() => instance.month(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal]
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[undefined, "undefined"], [undefined, "undefined"],
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
@ -20,8 +20,12 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [arg, description] of rangeErrorTests) { for (const [arg, description] of primitiveTests) {
assert.throws(RangeError, () => instance.month(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof arg === 'string' ? RangeError : TypeError,
() => instance.month(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -3,27 +3,23 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.monthcode esid: sec-temporal.calendar.prototype.monthcode
description: A number is converted to a string, then to Temporal.PlainDate description: A number cannot be used in place of a Temporal.PlainDate
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const arg = 19761118;
const result = instance.monthCode(arg);
assert.sameValue(result, "M11", "19761118 is a valid ISO string for PlainDate");
const numbers = [ const numbers = [
1, 1,
19761118,
-19761118, -19761118,
1234567890, 1234567890,
]; ];
for (const arg of numbers) { for (const arg of numbers) {
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.monthCode(arg), () => instance.monthCode(arg),
`Number ${arg} does not convert to a valid ISO string for PlainDate` 'Numbers cannot be used in place of an ISO string for PlainDate'
); );
} }

View File

@ -3,20 +3,15 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.monthcode esid: sec-temporal.calendar.prototype.monthcode
description: A number as calendar in a property bag is converted to a string, then to a calendar description: A number as calendar in a property bag is not accepted
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const calendar = 19970327;
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.monthCode(arg);
assert.sameValue(result, "M11", "19970327 is a valid ISO string for calendar");
const numbers = [ const numbers = [
1, 1,
19970327,
-19970327, -19970327,
1234567890, 1234567890,
]; ];
@ -24,8 +19,8 @@ const numbers = [
for (const calendar of numbers) { for (const calendar of numbers) {
const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.monthCode(arg), () => instance.monthCode(arg),
`Number ${calendar} does not convert to a valid ISO string for calendar` "Numbers cannot be used as a calendar"
); );
} }

View File

@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal]
const timeZone = new Temporal.TimeZone("UTC"); const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
["", "empty string"], ["", "empty string"],
@ -20,9 +20,13 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [calendar, description] of rangeErrorTests) { for (const [calendar, description] of primitiveTests) {
const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.monthCode(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof calendar === 'string' ? RangeError : TypeError,
() => instance.monthCode(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal]
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[undefined, "undefined"], [undefined, "undefined"],
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
@ -20,8 +20,12 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [arg, description] of rangeErrorTests) { for (const [arg, description] of primitiveTests) {
assert.throws(RangeError, () => instance.monthCode(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof arg === 'string' ? RangeError : TypeError,
() => instance.monthCode(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -3,27 +3,23 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.monthsinyear esid: sec-temporal.calendar.prototype.monthsinyear
description: A number is converted to a string, then to Temporal.PlainDate description: A number cannot be used in place of a Temporal.PlainDate
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const arg = 19761118;
const result = instance.monthsInYear(arg);
assert.sameValue(result, 12, "19761118 is a valid ISO string for PlainDate");
const numbers = [ const numbers = [
1, 1,
19761118,
-19761118, -19761118,
1234567890, 1234567890,
]; ];
for (const arg of numbers) { for (const arg of numbers) {
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.monthsInYear(arg), () => instance.monthsInYear(arg),
`Number ${arg} does not convert to a valid ISO string for PlainDate` 'Numbers cannot be used in place of an ISO string for PlainDate'
); );
} }

View File

@ -3,20 +3,15 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.monthsinyear esid: sec-temporal.calendar.prototype.monthsinyear
description: A number as calendar in a property bag is converted to a string, then to a calendar description: A number as calendar in a property bag is not accepted
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const calendar = 19970327;
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.monthsInYear(arg);
assert.sameValue(result, 12, "19970327 is a valid ISO string for calendar");
const numbers = [ const numbers = [
1, 1,
19970327,
-19970327, -19970327,
1234567890, 1234567890,
]; ];
@ -24,8 +19,8 @@ const numbers = [
for (const calendar of numbers) { for (const calendar of numbers) {
const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.monthsInYear(arg), () => instance.monthsInYear(arg),
`Number ${calendar} does not convert to a valid ISO string for calendar` "Numbers cannot be used as a calendar"
); );
} }

View File

@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal]
const timeZone = new Temporal.TimeZone("UTC"); const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
["", "empty string"], ["", "empty string"],
@ -20,9 +20,13 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [calendar, description] of rangeErrorTests) { for (const [calendar, description] of primitiveTests) {
const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.monthsInYear(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof calendar === 'string' ? RangeError : TypeError,
() => instance.monthsInYear(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal]
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[undefined, "undefined"], [undefined, "undefined"],
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
@ -20,8 +20,12 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [arg, description] of rangeErrorTests) { for (const [arg, description] of primitiveTests) {
assert.throws(RangeError, () => instance.monthsInYear(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof arg === 'string' ? RangeError : TypeError,
() => instance.monthsInYear(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -3,27 +3,23 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.weekofyear esid: sec-temporal.calendar.prototype.weekofyear
description: A number is converted to a string, then to Temporal.PlainDate description: A number cannot be used in place of a Temporal.PlainDate
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const arg = 19761118;
const result = instance.weekOfYear(arg);
assert.sameValue(result, 47, "19761118 is a valid ISO string for PlainDate");
const numbers = [ const numbers = [
1, 1,
19761118,
-19761118, -19761118,
1234567890, 1234567890,
]; ];
for (const arg of numbers) { for (const arg of numbers) {
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.weekOfYear(arg), () => instance.weekOfYear(arg),
`Number ${arg} does not convert to a valid ISO string for PlainDate` 'Numbers cannot be used in place of an ISO string for PlainDate'
); );
} }

View File

@ -3,20 +3,15 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.weekofyear esid: sec-temporal.calendar.prototype.weekofyear
description: A number as calendar in a property bag is converted to a string, then to a calendar description: A number as calendar in a property bag is not accepted
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const calendar = 19970327;
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.weekOfYear(arg);
assert.sameValue(result, 47, "19970327 is a valid ISO string for calendar");
const numbers = [ const numbers = [
1, 1,
19970327,
-19970327, -19970327,
1234567890, 1234567890,
]; ];
@ -24,8 +19,8 @@ const numbers = [
for (const calendar of numbers) { for (const calendar of numbers) {
const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.weekOfYear(arg), () => instance.weekOfYear(arg),
`Number ${calendar} does not convert to a valid ISO string for calendar` "Numbers cannot be used as a calendar"
); );
} }

View File

@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal]
const timeZone = new Temporal.TimeZone("UTC"); const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
["", "empty string"], ["", "empty string"],
@ -20,9 +20,13 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [calendar, description] of rangeErrorTests) { for (const [calendar, description] of primitiveTests) {
const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.weekOfYear(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof calendar === 'string' ? RangeError : TypeError,
() => instance.weekOfYear(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal]
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[undefined, "undefined"], [undefined, "undefined"],
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
@ -20,8 +20,12 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [arg, description] of rangeErrorTests) { for (const [arg, description] of primitiveTests) {
assert.throws(RangeError, () => instance.weekOfYear(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof arg === 'string' ? RangeError : TypeError,
() => instance.weekOfYear(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -3,27 +3,23 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.year esid: sec-temporal.calendar.prototype.year
description: A number is converted to a string, then to Temporal.PlainDate description: A number cannot be used in place of a Temporal.PlainDate
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const arg = 19761118;
const result = instance.year(arg);
assert.sameValue(result, 1976, "19761118 is a valid ISO string for PlainDate");
const numbers = [ const numbers = [
1, 1,
19761118,
-19761118, -19761118,
1234567890, 1234567890,
]; ];
for (const arg of numbers) { for (const arg of numbers) {
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.year(arg), () => instance.year(arg),
`Number ${arg} does not convert to a valid ISO string for PlainDate` 'Numbers cannot be used in place of an ISO string for PlainDate'
); );
} }

View File

@ -3,20 +3,15 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.year esid: sec-temporal.calendar.prototype.year
description: A number as calendar in a property bag is converted to a string, then to a calendar description: A number as calendar in a property bag is not accepted
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const calendar = 19970327;
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.year(arg);
assert.sameValue(result, 1976, "19970327 is a valid ISO string for calendar");
const numbers = [ const numbers = [
1, 1,
19970327,
-19970327, -19970327,
1234567890, 1234567890,
]; ];
@ -24,8 +19,8 @@ const numbers = [
for (const calendar of numbers) { for (const calendar of numbers) {
const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.year(arg), () => instance.year(arg),
`Number ${calendar} does not convert to a valid ISO string for calendar` "Numbers cannot be used as a calendar"
); );
} }

View File

@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal]
const timeZone = new Temporal.TimeZone("UTC"); const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
["", "empty string"], ["", "empty string"],
@ -20,9 +20,13 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [calendar, description] of rangeErrorTests) { for (const [calendar, description] of primitiveTests) {
const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.year(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof calendar === 'string' ? RangeError : TypeError,
() => instance.year(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal]
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[undefined, "undefined"], [undefined, "undefined"],
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
@ -20,8 +20,12 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [arg, description] of rangeErrorTests) { for (const [arg, description] of primitiveTests) {
assert.throws(RangeError, () => instance.year(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof arg === 'string' ? RangeError : TypeError,
() => instance.year(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -3,27 +3,23 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.yearofweek esid: sec-temporal.calendar.prototype.yearofweek
description: A number is converted to a string, then to Temporal.PlainDate description: A number cannot be used in place of a Temporal.PlainDate
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const arg = 19761118;
const result = instance.yearOfWeek(arg);
assert.sameValue(result, 1976, "19761118 is a valid ISO string for PlainDate");
const numbers = [ const numbers = [
1, 1,
19761118,
-19761118, -19761118,
1234567890, 1234567890,
]; ];
for (const arg of numbers) { for (const arg of numbers) {
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.yearOfWeek(arg), () => instance.yearOfWeek(arg),
`Number ${arg} does not convert to a valid ISO string for PlainDate` 'Numbers cannot be used in place of an ISO string for PlainDate'
); );
} }

View File

@ -3,20 +3,15 @@
/*--- /*---
esid: sec-temporal.calendar.prototype.yearofweek esid: sec-temporal.calendar.prototype.yearofweek
description: A number as calendar in a property bag is converted to a string, then to a calendar description: A number as calendar in a property bag is not accepted
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const calendar = 19970327;
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.yearOfWeek(arg);
assert.sameValue(result, 1976, "19970327 is a valid ISO string for calendar");
const numbers = [ const numbers = [
1, 1,
19970327,
-19970327, -19970327,
1234567890, 1234567890,
]; ];
@ -24,8 +19,8 @@ const numbers = [
for (const calendar of numbers) { for (const calendar of numbers) {
const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.yearOfWeek(arg), () => instance.yearOfWeek(arg),
`Number ${calendar} does not convert to a valid ISO string for calendar` "Numbers cannot be used as a calendar"
); );
} }

View File

@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal]
const timeZone = new Temporal.TimeZone("UTC"); const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
["", "empty string"], ["", "empty string"],
@ -20,9 +20,13 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [calendar, description] of rangeErrorTests) { for (const [calendar, description] of primitiveTests) {
const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.yearOfWeek(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof calendar === 'string' ? RangeError : TypeError,
() => instance.yearOfWeek(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal]
const instance = new Temporal.Calendar("iso8601"); const instance = new Temporal.Calendar("iso8601");
const rangeErrorTests = [ const primitiveTests = [
[undefined, "undefined"], [undefined, "undefined"],
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
@ -20,8 +20,12 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [arg, description] of rangeErrorTests) { for (const [arg, description] of primitiveTests) {
assert.throws(RangeError, () => instance.yearOfWeek(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof arg === 'string' ? RangeError : TypeError,
() => instance.yearOfWeek(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -15,9 +15,16 @@ const badOffsets = [
"00:00", // missing sign "00:00", // missing sign
"+0", // too short "+0", // too short
"-000:00", // too long "-000:00", // too long
0, // converts to a string that is invalid 1000, // must be a string
null, // must be a string
true, // must be a string
1000n, // must be a string
]; ];
badOffsets.forEach((offset) => { badOffsets.forEach((offset) => {
const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone }; const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone };
assert.throws(RangeError, () => Temporal.Duration.compare(d1, d2, { relativeTo }), `"${offset} is not a valid offset string`); assert.throws(
typeof(offset) === 'string' ? RangeError : TypeError,
() => Temporal.Duration.compare(d1, d2, { relativeTo }),
`"${offset} is not a valid offset string`
);
}); });

View File

@ -9,7 +9,7 @@ description: >
features: [BigInt, Symbol, Temporal] features: [BigInt, Symbol, Temporal]
---*/ ---*/
const rangeErrorTests = [ const primitiveTests = [
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
["", "empty string"], ["", "empty string"],
@ -18,8 +18,12 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [timeZone, description] of rangeErrorTests) { for (const [timeZone, description] of primitiveTests) {
assert.throws(RangeError, () => Temporal.Duration.compare(new Temporal.Duration(), new Temporal.Duration(), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), `${description} does not convert to a valid ISO string`); assert.throws(
typeof timeZone === 'string' ? RangeError : TypeError,
() => Temporal.Duration.compare(new Temporal.Duration(), new Temporal.Duration(), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -7,9 +7,9 @@ description: Appropriate error thrown if primitive input cannot convert to a val
features: [Temporal] features: [Temporal]
---*/ ---*/
assert.throws(RangeError, () => Temporal.Duration.from(undefined), "undefined"); assert.throws(TypeError, () => Temporal.Duration.from(undefined), "undefined");
assert.throws(RangeError, () => Temporal.Duration.from(null), "null"); assert.throws(TypeError, () => Temporal.Duration.from(null), "null");
assert.throws(RangeError, () => Temporal.Duration.from(true), "boolean"); assert.throws(TypeError, () => Temporal.Duration.from(true), "boolean");
assert.throws(TypeError, () => Temporal.Duration.from(Symbol()), "Symbol"); assert.throws(TypeError, () => Temporal.Duration.from(Symbol()), "Symbol");
assert.throws(RangeError, () => Temporal.Duration.from(5), "number"); assert.throws(TypeError, () => Temporal.Duration.from(5), "number");
assert.throws(RangeError, () => Temporal.Duration.from(5n), "bigint"); assert.throws(TypeError, () => Temporal.Duration.from(5n), "bigint");

View File

@ -8,12 +8,12 @@ features: [Symbol, Temporal]
---*/ ---*/
const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321); const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321);
assert.throws(RangeError, () => instance.add(undefined), "undefined"); assert.throws(TypeError, () => instance.add(undefined), "undefined");
assert.throws(RangeError, () => instance.add(null), "null"); assert.throws(TypeError, () => instance.add(null), "null");
assert.throws(RangeError, () => instance.add(true), "boolean"); assert.throws(TypeError, () => instance.add(true), "boolean");
assert.throws(RangeError, () => instance.add(""), "empty string"); assert.throws(RangeError, () => instance.add(""), "empty string");
assert.throws(TypeError, () => instance.add(Symbol()), "Symbol"); assert.throws(TypeError, () => instance.add(Symbol()), "Symbol");
assert.throws(RangeError, () => instance.add(7), "number"); assert.throws(TypeError, () => instance.add(7), "number");
assert.throws(RangeError, () => instance.add(7n), "bigint"); assert.throws(TypeError, () => instance.add(7n), "bigint");
assert.throws(TypeError, () => instance.add([]), "array"); assert.throws(TypeError, () => instance.add([]), "array");
assert.throws(TypeError, () => instance.add(() => {}), "function"); assert.throws(TypeError, () => instance.add(() => {}), "function");

View File

@ -4,7 +4,6 @@
/*--- /*---
esid: sec-temporal.duration.prototype.add esid: sec-temporal.duration.prototype.add
description: A number as relativeTo option is converted to a string, then to Temporal.PlainDate description: A number as relativeTo option is converted to a string, then to Temporal.PlainDate
includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
@ -12,18 +11,16 @@ const instance = new Temporal.Duration(1, 0, 0, 1);
const relativeTo = 20191101; const relativeTo = 20191101;
const result = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo });
TemporalHelpers.assertDuration(result, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "20191101 is a valid ISO string for relativeTo");
const numbers = [ const numbers = [
1, 1,
-20191101, -20191101,
20191101,
1234567890, 1234567890,
]; ];
for (const relativeTo of numbers) { for (const relativeTo of numbers) {
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }),
`Number ${relativeTo} does not convert to a valid ISO string for relativeTo` `Number ${relativeTo} does not convert to a valid ISO string for relativeTo`
); );

View File

@ -4,20 +4,14 @@
/*--- /*---
esid: sec-temporal.duration.prototype.add esid: sec-temporal.duration.prototype.add
description: A number as calendar in relativeTo property bag is converted to a string, then to a calendar description: A number as calendar in relativeTo property bag is converted to a string, then to a calendar
includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Duration(1, 0, 0, 1); const instance = new Temporal.Duration(1, 0, 0, 1);
const calendar = 19970327;
const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar };
const result = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo });
TemporalHelpers.assertDuration(result, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for relativeTo.calendar");
const numbers = [ const numbers = [
1, 1,
19970327,
-19970327, -19970327,
1234567890, 1234567890,
]; ];
@ -25,8 +19,8 @@ const numbers = [
for (const calendar of numbers) { for (const calendar of numbers) {
const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }),
`Number ${calendar} does not convert to a valid ISO string for relativeTo.calendar` "A number is not a valid ISO string for relativeTo.calendar"
); );
} }

View File

@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal]
const timeZone = new Temporal.TimeZone("UTC"); const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Duration(1, 0, 0, 1); const instance = new Temporal.Duration(1, 0, 0, 1);
const rangeErrorTests = [ const primitiveTests = [
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
["", "empty string"], ["", "empty string"],
@ -20,9 +20,13 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [calendar, description] of rangeErrorTests) { for (const [calendar, description] of primitiveTests) {
const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), `${description} does not convert to a valid ISO string`); assert.throws(
typeof calendar === 'string' ? RangeError : TypeError,
() => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -14,9 +14,16 @@ const badOffsets = [
"00:00", // missing sign "00:00", // missing sign
"+0", // too short "+0", // too short
"-000:00", // too long "-000:00", // too long
0, // converts to a string that is invalid 0, // must be a string
null, // must be a string
true, // must be a string
1000n, // must be a string
]; ];
badOffsets.forEach((offset) => { badOffsets.forEach((offset) => {
const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone }; const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone };
assert.throws(RangeError, () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), `"${offset} is not a valid offset string`); assert.throws(
typeof(offset) === 'string' ? RangeError : TypeError,
() => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }),
`"${offset} is not a valid offset string`
);
}); });

View File

@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal]
const instance = new Temporal.Duration(1); const instance = new Temporal.Duration(1);
const rangeErrorTests = [ const primitiveTests = [
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
["", "empty string"], ["", "empty string"],
@ -20,8 +20,12 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [timeZone, description] of rangeErrorTests) { for (const [timeZone, description] of primitiveTests) {
assert.throws(RangeError, () => instance.add(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), `${description} does not convert to a valid ISO string`); assert.throws(
typeof timeZone === 'string' ? RangeError : TypeError,
() => instance.add(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal]
const timeZone = new Temporal.TimeZone("UTC"); const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Duration(1, 0, 0, 1); const instance = new Temporal.Duration(1, 0, 0, 1);
const rangeErrorTests = [ const primitiveTests = [
[undefined, "undefined"], [undefined, "undefined"],
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
@ -21,8 +21,12 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [relativeTo, description] of rangeErrorTests) { for (const [relativeTo, description] of primitiveTests) {
assert.throws(RangeError, () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), `${description} does not convert to a valid ISO string`); assert.throws(
typeof relativeTo === 'string' || typeof relativeTo === 'undefined' ? RangeError : TypeError,
() => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }),
`${description} does not convert to a valid ISO string (first argument)`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -4,7 +4,6 @@
/*--- /*---
esid: sec-temporal.duration.prototype.round esid: sec-temporal.duration.prototype.round
description: A number as relativeTo option is converted to a string, then to Temporal.PlainDate description: A number as relativeTo option is converted to a string, then to Temporal.PlainDate
includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
@ -12,18 +11,16 @@ const instance = new Temporal.Duration(1, 0, 0, 0, 24);
const relativeTo = 20191101; const relativeTo = 20191101;
const result = instance.round({ largestUnit: "years", relativeTo });
TemporalHelpers.assertDuration(result, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "20191101 is a valid ISO string for relativeTo");
const numbers = [ const numbers = [
1, 1,
20191101,
-20191101, -20191101,
1234567890, 1234567890,
]; ];
for (const relativeTo of numbers) { for (const relativeTo of numbers) {
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.round({ largestUnit: "years", relativeTo }), () => instance.round({ largestUnit: "years", relativeTo }),
`Number ${relativeTo} does not convert to a valid ISO string for relativeTo` `Number ${relativeTo} does not convert to a valid ISO string for relativeTo`
); );

View File

@ -3,21 +3,15 @@
/*--- /*---
esid: sec-temporal.duration.prototype.round esid: sec-temporal.duration.prototype.round
description: A number as calendar in relativeTo property bag is converted to a string, then to a calendar description: A number as calendar in relativeTo property bag is invalid
includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Duration(1, 0, 0, 0, 24); const instance = new Temporal.Duration(1, 0, 0, 0, 24);
const calendar = 19970327;
const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar };
const result = instance.round({ largestUnit: "years", relativeTo });
TemporalHelpers.assertDuration(result, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for relativeTo.calendar");
const numbers = [ const numbers = [
1, 1,
19970327,
-19970327, -19970327,
1234567890, 1234567890,
]; ];
@ -25,8 +19,8 @@ const numbers = [
for (const calendar of numbers) { for (const calendar of numbers) {
const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.round({ largestUnit: "years", relativeTo }), () => instance.round({ largestUnit: "years", relativeTo }),
`Number ${calendar} does not convert to a valid ISO string for relativeTo.calendar` "A number is not a valid ISO string for relativeTo.calendar"
); );
} }

View File

@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal]
const timeZone = new Temporal.TimeZone("UTC"); const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Duration(1, 0, 0, 0, 24); const instance = new Temporal.Duration(1, 0, 0, 0, 24);
const rangeErrorTests = [ const primitiveTests = [
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
["", "empty string"], ["", "empty string"],
@ -20,9 +20,13 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [calendar, description] of rangeErrorTests) { for (const [calendar, description] of primitiveTests) {
const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.round({ largestUnit: "years", relativeTo }), `${description} does not convert to a valid ISO string`); assert.throws(
typeof calendar === 'string' ? RangeError : TypeError,
() => instance.round({ largestUnit: "years", relativeTo }),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -14,9 +14,16 @@ const badOffsets = [
"00:00", // missing sign "00:00", // missing sign
"+0", // too short "+0", // too short
"-000:00", // too long "-000:00", // too long
0, // converts to a string that is invalid 0, // must be a string
null, // must be a string
true, // must be a string
1000n, // must be a string
]; ];
badOffsets.forEach((offset) => { badOffsets.forEach((offset) => {
const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone }; const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone };
assert.throws(RangeError, () => instance.round({ largestUnit: "years", relativeTo }), `"${offset} is not a valid offset string`); assert.throws(
typeof(offset) === 'string' ? RangeError : TypeError,
() => instance.round({ largestUnit: "years", relativeTo }),
`"${offset} is not a valid offset string`
);
}); });

View File

@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal]
const instance = new Temporal.Duration(1); const instance = new Temporal.Duration(1);
const rangeErrorTests = [ const primitiveTests = [
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
["", "empty string"], ["", "empty string"],
@ -20,8 +20,12 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [timeZone, description] of rangeErrorTests) { for (const [timeZone, description] of primitiveTests) {
assert.throws(RangeError, () => instance.round({ largestUnit: "months", relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), `${description} does not convert to a valid ISO string`); assert.throws(
typeof timeZone === 'string' ? RangeError : TypeError,
() => instance.round({ largestUnit: "months", relativeTo: { year: 2000, month: 5, day: 2, timeZone } }),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -9,31 +9,39 @@ description: >
features: [BigInt, Symbol, Temporal] features: [BigInt, Symbol, Temporal]
---*/ ---*/
const timeZone = new Temporal.TimeZone("UTC"); const timeZone = new Temporal.TimeZone('UTC');
const instance = new Temporal.Duration(1, 0, 0, 0, 24); const instance = new Temporal.Duration(1, 0, 0, 0, 24);
const rangeErrorTests = [ const primitiveTests = [
[undefined, "undefined"], [undefined, 'undefined'],
[null, "null"], [null, 'null'],
[true, "boolean"], [true, 'boolean'],
["", "empty string"], ['', 'empty string'],
[1, "number that doesn't convert to a valid ISO string"], [1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"], [1n, 'bigint']
]; ];
for (const [relativeTo, description] of rangeErrorTests) { for (const [relativeTo, description] of primitiveTests) {
assert.throws(RangeError, () => instance.round({ largestUnit: "years", relativeTo }), `${description} does not convert to a valid ISO string`); assert.throws(
typeof relativeTo === 'string' || typeof relativeTo === 'undefined' ? RangeError : TypeError,
() => instance.round({ largestUnit: 'years', relativeTo }),
`${description} does not convert to a valid ISO string (first argument)`
);
} }
const typeErrorTests = [ const typeErrorTests = [
[Symbol(), "symbol"], [Symbol(), 'symbol'],
[{}, "plain object"], [{}, 'plain object'],
[Temporal.PlainDate, "Temporal.PlainDate, object"], [Temporal.PlainDate, 'Temporal.PlainDate, object'],
[Temporal.PlainDate.prototype, "Temporal.PlainDate.prototype, object"], [Temporal.PlainDate.prototype, 'Temporal.PlainDate.prototype, object'],
[Temporal.ZonedDateTime, "Temporal.ZonedDateTime, object"], [Temporal.ZonedDateTime, 'Temporal.ZonedDateTime, object'],
[Temporal.ZonedDateTime.prototype, "Temporal.ZonedDateTime.prototype, object"], [Temporal.ZonedDateTime.prototype, 'Temporal.ZonedDateTime.prototype, object']
]; ];
for (const [relativeTo, description] of typeErrorTests) { for (const [relativeTo, description] of typeErrorTests) {
assert.throws(TypeError, () => instance.round({ largestUnit: "years", relativeTo }), `${description} is not a valid property bag and does not convert to a string`); assert.throws(
TypeError,
() => instance.round({ largestUnit: 'years', relativeTo }),
`${description} is not a valid property bag and does not convert to a string`
);
} }

View File

@ -8,12 +8,12 @@ features: [Symbol, Temporal]
---*/ ---*/
const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321); const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321);
assert.throws(RangeError, () => instance.subtract(undefined), "undefined"); assert.throws(TypeError, () => instance.subtract(undefined), "undefined");
assert.throws(RangeError, () => instance.subtract(null), "null"); assert.throws(TypeError, () => instance.subtract(null), "null");
assert.throws(RangeError, () => instance.subtract(true), "boolean"); assert.throws(TypeError, () => instance.subtract(true), "boolean");
assert.throws(RangeError, () => instance.subtract(""), "empty string"); assert.throws(RangeError, () => instance.subtract(""), "empty string");
assert.throws(TypeError, () => instance.subtract(Symbol()), "Symbol"); assert.throws(TypeError, () => instance.subtract(Symbol()), "Symbol");
assert.throws(RangeError, () => instance.subtract(7), "number"); assert.throws(TypeError, () => instance.subtract(7), "number");
assert.throws(RangeError, () => instance.subtract(7n), "bigint"); assert.throws(TypeError, () => instance.subtract(7n), "bigint");
assert.throws(TypeError, () => instance.subtract([]), "array"); assert.throws(TypeError, () => instance.subtract([]), "array");
assert.throws(TypeError, () => instance.subtract(() => {}), "function"); assert.throws(TypeError, () => instance.subtract(() => {}), "function");

View File

@ -4,7 +4,6 @@
/*--- /*---
esid: sec-temporal.duration.prototype.subtract esid: sec-temporal.duration.prototype.subtract
description: A number as relativeTo option is converted to a string, then to Temporal.PlainDate description: A number as relativeTo option is converted to a string, then to Temporal.PlainDate
includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
@ -12,18 +11,16 @@ const instance = new Temporal.Duration(1, 0, 0, 1);
const relativeTo = 20191101; const relativeTo = 20191101;
const result = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo });
TemporalHelpers.assertDuration(result, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "20191101 is a valid ISO string for relativeTo");
const numbers = [ const numbers = [
1, 1,
20191101,
-20191101, -20191101,
1234567890, 1234567890,
]; ];
for (const relativeTo of numbers) { for (const relativeTo of numbers) {
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }),
`Number ${relativeTo} does not convert to a valid ISO string for relativeTo` `Number ${relativeTo} does not convert to a valid ISO string for relativeTo`
); );

View File

@ -3,8 +3,7 @@
/*--- /*---
esid: sec-temporal.duration.prototype.subtract esid: sec-temporal.duration.prototype.subtract
description: A number as calendar in relativeTo property bag is converted to a string, then to a calendar description: A number as calendar in relativeTo property bag is invalid
includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
@ -12,12 +11,9 @@ const instance = new Temporal.Duration(1, 0, 0, 1);
const calendar = 19970327; const calendar = 19970327;
const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar };
const result = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo });
TemporalHelpers.assertDuration(result, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for relativeTo.calendar");
const numbers = [ const numbers = [
1, 1,
19970327,
-19970327, -19970327,
1234567890, 1234567890,
]; ];
@ -25,8 +21,8 @@ const numbers = [
for (const calendar of numbers) { for (const calendar of numbers) {
const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }),
`Number ${calendar} does not convert to a valid ISO string for relativeTo.calendar` "A number is not a valid ISO string for relativeTo.calendar"
); );
} }

View File

@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal]
const timeZone = new Temporal.TimeZone("UTC"); const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Duration(1, 0, 0, 1); const instance = new Temporal.Duration(1, 0, 0, 1);
const rangeErrorTests = [ const primitiveTests = [
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
["", "empty string"], ["", "empty string"],
@ -20,9 +20,13 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [calendar, description] of rangeErrorTests) { for (const [calendar, description] of primitiveTests) {
const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), `${description} does not convert to a valid ISO string`); assert.throws(
typeof calendar === 'string' ? RangeError : TypeError,
() => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -14,9 +14,16 @@ const badOffsets = [
"00:00", // missing sign "00:00", // missing sign
"+0", // too short "+0", // too short
"-000:00", // too long "-000:00", // too long
0, // converts to a string that is invalid 0, // must be a string
null, // must be a string
true, // must be a string
1000n, // must be a string
]; ];
badOffsets.forEach((offset) => { badOffsets.forEach((offset) => {
const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone }; const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone };
assert.throws(RangeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), `"${offset} is not a valid offset string`); assert.throws(
typeof(offset) === 'string' ? RangeError : TypeError,
() => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24),
{ relativeTo }), `"${offset} is not a valid offset string`
);
}); });

View File

@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal]
const instance = new Temporal.Duration(1); const instance = new Temporal.Duration(1);
const rangeErrorTests = [ const primitiveTests = [
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
["", "empty string"], ["", "empty string"],
@ -20,8 +20,12 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [timeZone, description] of rangeErrorTests) { for (const [timeZone, description] of primitiveTests) {
assert.throws(RangeError, () => instance.subtract(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), `${description} does not convert to a valid ISO string`); assert.throws(
typeof timeZone === 'string' ? RangeError : TypeError,
() => instance.subtract(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -9,31 +9,39 @@ description: >
features: [BigInt, Symbol, Temporal] features: [BigInt, Symbol, Temporal]
---*/ ---*/
const timeZone = new Temporal.TimeZone("UTC"); const timeZone = new Temporal.TimeZone('UTC');
const instance = new Temporal.Duration(1, 0, 0, 1); const instance = new Temporal.Duration(1, 0, 0, 1);
const rangeErrorTests = [ const primitiveTests = [
[undefined, "undefined"], [undefined, 'undefined'],
[null, "null"], [null, 'null'],
[true, "boolean"], [true, 'boolean'],
["", "empty string"], ['', 'empty string'],
[1, "number that doesn't convert to a valid ISO string"], [1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"], [1n, 'bigint']
]; ];
for (const [relativeTo, description] of rangeErrorTests) { for (const [relativeTo, description] of primitiveTests) {
assert.throws(RangeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), `${description} does not convert to a valid ISO string`); assert.throws(
typeof relativeTo === 'string' || typeof relativeTo === 'undefined' ? RangeError : TypeError,
() => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }),
`${description} does not convert to a valid ISO string (first argument)`
);
} }
const typeErrorTests = [ const typeErrorTests = [
[Symbol(), "symbol"], [Symbol(), 'symbol'],
[{}, "plain object"], [{}, 'plain object'],
[Temporal.PlainDate, "Temporal.PlainDate, object"], [Temporal.PlainDate, 'Temporal.PlainDate, object'],
[Temporal.PlainDate.prototype, "Temporal.PlainDate.prototype, object"], [Temporal.PlainDate.prototype, 'Temporal.PlainDate.prototype, object'],
[Temporal.ZonedDateTime, "Temporal.ZonedDateTime, object"], [Temporal.ZonedDateTime, 'Temporal.ZonedDateTime, object'],
[Temporal.ZonedDateTime.prototype, "Temporal.ZonedDateTime.prototype, object"], [Temporal.ZonedDateTime.prototype, 'Temporal.ZonedDateTime.prototype, object']
]; ];
for (const [relativeTo, description] of typeErrorTests) { for (const [relativeTo, description] of typeErrorTests) {
assert.throws(TypeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), `${description} is not a valid property bag and does not convert to a string`); assert.throws(
TypeError,
() => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }),
`${description} is not a valid property bag and does not convert to a string`
);
} }

View File

@ -11,18 +11,16 @@ const instance = new Temporal.Duration(1, 0, 0, 0, 24);
const relativeTo = 20191101; const relativeTo = 20191101;
const result = instance.total({ unit: "days", relativeTo });
assert.sameValue(result, 367, "20191101 is a valid ISO string for relativeTo");
const numbers = [ const numbers = [
1, 1,
20191101,
-20191101, -20191101,
1234567890, 1234567890,
]; ];
for (const relativeTo of numbers) { for (const relativeTo of numbers) {
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.total({ unit: "days", relativeTo }), () => instance.total({ unit: "days", relativeTo }),
`Number ${relativeTo} does not convert to a valid ISO string for relativeTo` `Number ${relativeTo} does not convert to a valid ISO string for relativeTo`
); );

View File

@ -3,20 +3,15 @@
/*--- /*---
esid: sec-temporal.duration.prototype.total esid: sec-temporal.duration.prototype.total
description: A number as calendar in relativeTo property bag is converted to a string, then to a calendar description: A number as calendar in relativeTo property bag is invalid
features: [Temporal] features: [Temporal]
---*/ ---*/
const instance = new Temporal.Duration(1, 0, 0, 0, 24); const instance = new Temporal.Duration(1, 0, 0, 0, 24);
const calendar = 19970327;
const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar };
const result = instance.total({ unit: "days", relativeTo });
assert.sameValue(result, 367, "19970327 is a valid ISO string for relativeTo.calendar");
const numbers = [ const numbers = [
1, 1,
19970327,
-19970327, -19970327,
1234567890, 1234567890,
]; ];
@ -24,8 +19,8 @@ const numbers = [
for (const calendar of numbers) { for (const calendar of numbers) {
const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws( assert.throws(
RangeError, TypeError,
() => instance.total({ unit: "days", relativeTo }), () => instance.total({ unit: "days", relativeTo }),
`Number ${calendar} does not convert to a valid ISO string for relativeTo.calendar` "A number is not a valid ISO string for relativeTo.calendar"
); );
} }

View File

@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal]
const timeZone = new Temporal.TimeZone("UTC"); const timeZone = new Temporal.TimeZone("UTC");
const instance = new Temporal.Duration(1, 0, 0, 0, 24); const instance = new Temporal.Duration(1, 0, 0, 0, 24);
const rangeErrorTests = [ const primitiveTests = [
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
["", "empty string"], ["", "empty string"],
@ -20,9 +20,13 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [calendar, description] of rangeErrorTests) { for (const [calendar, description] of primitiveTests) {
const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.total({ unit: "days", relativeTo }), `${description} does not convert to a valid ISO string`); assert.throws(
typeof calendar === 'string' ? RangeError : TypeError,
() => instance.total({ unit: "days", relativeTo }),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -14,9 +14,16 @@ const badOffsets = [
"00:00", // missing sign "00:00", // missing sign
"+0", // too short "+0", // too short
"-000:00", // too long "-000:00", // too long
0, // converts to a string that is invalid 0, // must be a string
null, // must be a string
true, // must be a string
1000n, // must be a string
]; ];
badOffsets.forEach((offset) => { badOffsets.forEach((offset) => {
const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone }; const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone };
assert.throws(RangeError, () => instance.total({ unit: "days", relativeTo }), `"${offset} is not a valid offset string`); assert.throws(
typeof(offset) === 'string' ? RangeError : TypeError,
() => instance.total({ unit: "days", relativeTo }),
`"${offset} is not a valid offset string`
);
}); });

View File

@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal]
const instance = new Temporal.Duration(1); const instance = new Temporal.Duration(1);
const rangeErrorTests = [ const primitiveTests = [
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
["", "empty string"], ["", "empty string"],
@ -20,8 +20,12 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [timeZone, description] of rangeErrorTests) { for (const [timeZone, description] of primitiveTests) {
assert.throws(RangeError, () => instance.total({ unit: "months", relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), `${description} does not convert to a valid ISO string`); assert.throws(
typeof timeZone === 'string' ? RangeError : TypeError,
() => instance.total({ unit: "months", relativeTo: { year: 2000, month: 5, day: 2, timeZone } }),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -9,31 +9,39 @@ description: >
features: [BigInt, Symbol, Temporal] features: [BigInt, Symbol, Temporal]
---*/ ---*/
const timeZone = new Temporal.TimeZone("UTC"); const timeZone = new Temporal.TimeZone('UTC');
const instance = new Temporal.Duration(1, 0, 0, 0, 24); const instance = new Temporal.Duration(1, 0, 0, 0, 24);
const rangeErrorTests = [ const primitiveTests = [
[undefined, "undefined"], [undefined, 'undefined'],
[null, "null"], [null, 'null'],
[true, "boolean"], [true, 'boolean'],
["", "empty string"], ['', 'empty string'],
[1, "number that doesn't convert to a valid ISO string"], [1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"], [1n, 'bigint']
]; ];
for (const [relativeTo, description] of rangeErrorTests) { for (const [relativeTo, description] of primitiveTests) {
assert.throws(RangeError, () => instance.total({ unit: "days", relativeTo }), `${description} does not convert to a valid ISO string`); assert.throws(
typeof relativeTo === 'string' || typeof relativeTo === 'undefined' ? RangeError : TypeError,
() => instance.total({ unit: 'days', relativeTo }),
`${description} does not convert to a valid ISO string (first argument)`
);
} }
const typeErrorTests = [ const typeErrorTests = [
[Symbol(), "symbol"], [Symbol(), 'symbol'],
[{}, "plain object"], [{}, 'plain object'],
[Temporal.PlainDate, "Temporal.PlainDate, object"], [Temporal.PlainDate, 'Temporal.PlainDate, object'],
[Temporal.PlainDate.prototype, "Temporal.PlainDate.prototype, object"], [Temporal.PlainDate.prototype, 'Temporal.PlainDate.prototype, object'],
[Temporal.ZonedDateTime, "Temporal.ZonedDateTime, object"], [Temporal.ZonedDateTime, 'Temporal.ZonedDateTime, object'],
[Temporal.ZonedDateTime.prototype, "Temporal.ZonedDateTime.prototype, object"], [Temporal.ZonedDateTime.prototype, 'Temporal.ZonedDateTime.prototype, object']
]; ];
for (const [relativeTo, description] of typeErrorTests) { for (const [relativeTo, description] of typeErrorTests) {
assert.throws(TypeError, () => instance.total({ unit: "days", relativeTo }), `${description} is not a valid property bag and does not convert to a string`); assert.throws(
TypeError,
() => instance.total({ unit: 'days', relativeTo }),
`${description} is not a valid property bag and does not convert to a string`
);
} }

View File

@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal]
const other = new Temporal.Instant(0n); const other = new Temporal.Instant(0n);
const rangeErrorTests = [ const primitiveTests = [
[undefined, "undefined"], [undefined, "undefined"],
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
@ -20,20 +20,40 @@ const rangeErrorTests = [
[19761118, "number that would convert to a valid ISO string in other contexts"], [19761118, "number that would convert to a valid ISO string in other contexts"],
[1n, "bigint"], [1n, "bigint"],
[{}, "plain object"], [{}, "plain object"],
[Temporal.Instant, "Temporal.Instant, object"], [Temporal.Instant, "Temporal.Instant, object"]
]; ];
for (const [arg, description] of rangeErrorTests) { for (const [arg, description] of primitiveTests) {
assert.throws(RangeError, () => Temporal.Instant.compare(arg, other), `${description} does not convert to a valid ISO string (first argument)`); assert.throws(
assert.throws(RangeError, () => Temporal.Instant.compare(other, arg), `${description} does not convert to a valid ISO string (second argument)`); typeof arg === "string" || (typeof arg === "object" && arg !== null) || typeof arg === "function"
? RangeError
: TypeError,
() => Temporal.Instant.compare(arg, other),
`${description} does not convert to a valid ISO string (first argument)`
);
assert.throws(
typeof arg === "string" || (typeof arg === "object" && arg !== null) || typeof arg === "function"
? RangeError
: TypeError,
() => Temporal.Instant.compare(other, arg),
`${description} does not convert to a valid ISO string (second argument)`
);
} }
const typeErrorTests = [ const typeErrorTests = [
[Symbol(), "symbol"], [Symbol(), "symbol"],
[Temporal.Instant.prototype, "Temporal.Instant.prototype, object"], // fails brand check in toString() [Temporal.Instant.prototype, "Temporal.Instant.prototype, object"] // fails brand check in toString()
]; ];
for (const [arg, description] of typeErrorTests) { for (const [arg, description] of typeErrorTests) {
assert.throws(TypeError, () => Temporal.Instant.compare(arg, other), `${description} does not convert to a string (first argument)`); assert.throws(
assert.throws(TypeError, () => Temporal.Instant.compare(other, arg), `${description} does not convert to a string (second argument)`); TypeError,
() => Temporal.Instant.compare(arg, other),
`${description} does not convert to a string (first argument)`
);
assert.throws(
TypeError,
() => Temporal.Instant.compare(other, arg),
`${description} does not convert to a string (second argument)`
);
} }

View File

@ -9,25 +9,31 @@ description: >
features: [BigInt, Symbol, Temporal] features: [BigInt, Symbol, Temporal]
---*/ ---*/
const rangeErrorTests = [ const primitiveTests = [
[undefined, "undefined"], [undefined, 'undefined'],
[null, "null"], [null, 'null'],
[true, "boolean"], [true, 'boolean'],
["", "empty string"], ['', 'empty string'],
[1, "number that doesn't convert to a valid ISO string"], [1, "number that doesn't convert to a valid ISO string"],
[19761118, "number that would convert to a valid ISO string in other contexts"], [19761118, 'number that would convert to a valid ISO string in other contexts'],
[1n, "bigint"], [1n, 'bigint'],
[{}, "plain object"], [{}, 'plain object'],
[Temporal.Instant, "Temporal.Instant, object"], [Temporal.Instant, 'Temporal.Instant, object']
]; ];
for (const [arg, description] of rangeErrorTests) { for (const [arg, description] of primitiveTests) {
assert.throws(RangeError, () => Temporal.Instant.from(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof arg === 'string' || (typeof arg === 'object' && arg !== null) || typeof arg === 'function'
? RangeError
: TypeError,
() => Temporal.Instant.from(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [
[Symbol(), "symbol"], [Symbol(), 'symbol'],
[Temporal.Instant.prototype, "Temporal.Instant.prototype, object"], // fails brand check in toString() [Temporal.Instant.prototype, 'Temporal.Instant.prototype, object'] // fails brand check in toString()
]; ];
for (const [arg, description] of typeErrorTests) { for (const [arg, description] of typeErrorTests) {

View File

@ -8,12 +8,12 @@ features: [Symbol, Temporal]
---*/ ---*/
const instance = new Temporal.Instant(1_000_000_000_000_000_000n); const instance = new Temporal.Instant(1_000_000_000_000_000_000n);
assert.throws(RangeError, () => instance.add(undefined), "undefined"); assert.throws(TypeError, () => instance.add(undefined), "undefined");
assert.throws(RangeError, () => instance.add(null), "null"); assert.throws(TypeError, () => instance.add(null), "null");
assert.throws(RangeError, () => instance.add(true), "boolean"); assert.throws(TypeError, () => instance.add(true), "boolean");
assert.throws(RangeError, () => instance.add(""), "empty string"); assert.throws(RangeError, () => instance.add(""), "empty string");
assert.throws(TypeError, () => instance.add(Symbol()), "Symbol"); assert.throws(TypeError, () => instance.add(Symbol()), "Symbol");
assert.throws(RangeError, () => instance.add(7), "number"); assert.throws(TypeError, () => instance.add(7), "number");
assert.throws(RangeError, () => instance.add(7n), "bigint"); assert.throws(TypeError, () => instance.add(7n), "bigint");
assert.throws(TypeError, () => instance.add([]), "array"); assert.throws(TypeError, () => instance.add([]), "array");
assert.throws(TypeError, () => instance.add(() => {}), "function"); assert.throws(TypeError, () => instance.add(() => {}), "function");

View File

@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal]
const instance = new Temporal.Instant(0n); const instance = new Temporal.Instant(0n);
const rangeErrorTests = [ const primitiveTests = [
[undefined, "undefined"], [undefined, "undefined"],
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
@ -23,8 +23,14 @@ const rangeErrorTests = [
[Temporal.Instant, "Temporal.Instant, object"], [Temporal.Instant, "Temporal.Instant, object"],
]; ];
for (const [arg, description] of rangeErrorTests) { for (const [arg, description] of primitiveTests) {
assert.throws(RangeError, () => instance.equals(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof arg === "string" || (typeof arg === "object" && arg !== null) || typeof arg === "function"
? RangeError
: TypeError,
() => instance.equals(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal]
const instance = new Temporal.Instant(0n); const instance = new Temporal.Instant(0n);
const rangeErrorTests = [ const primitiveTests = [
[undefined, "undefined"], [undefined, "undefined"],
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
@ -23,8 +23,14 @@ const rangeErrorTests = [
[Temporal.Instant, "Temporal.Instant, object"], [Temporal.Instant, "Temporal.Instant, object"],
]; ];
for (const [arg, description] of rangeErrorTests) { for (const [arg, description] of primitiveTests) {
assert.throws(RangeError, () => instance.since(arg), `${description} does not convert to a valid ISO string`); assert.throws(
typeof arg === "string" || (typeof arg === "object" && arg !== null) || typeof arg === "function"
? RangeError
: TypeError,
() => instance.since(arg),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

View File

@ -8,12 +8,12 @@ features: [Symbol, Temporal]
---*/ ---*/
const instance = new Temporal.Instant(1_000_000_000_000_000_000n); const instance = new Temporal.Instant(1_000_000_000_000_000_000n);
assert.throws(RangeError, () => instance.subtract(undefined), "undefined"); assert.throws(TypeError, () => instance.subtract(undefined), "undefined");
assert.throws(RangeError, () => instance.subtract(null), "null"); assert.throws(TypeError, () => instance.subtract(null), "null");
assert.throws(RangeError, () => instance.subtract(true), "boolean"); assert.throws(TypeError, () => instance.subtract(true), "boolean");
assert.throws(RangeError, () => instance.subtract(""), "empty string"); assert.throws(RangeError, () => instance.subtract(""), "empty string");
assert.throws(TypeError, () => instance.subtract(Symbol()), "Symbol"); assert.throws(TypeError, () => instance.subtract(Symbol()), "Symbol");
assert.throws(RangeError, () => instance.subtract(7), "number"); assert.throws(TypeError, () => instance.subtract(7), "number");
assert.throws(RangeError, () => instance.subtract(7n), "bigint"); assert.throws(TypeError, () => instance.subtract(7n), "bigint");
assert.throws(TypeError, () => instance.subtract([]), "array"); assert.throws(TypeError, () => instance.subtract([]), "array");
assert.throws(TypeError, () => instance.subtract(() => {}), "function"); assert.throws(TypeError, () => instance.subtract(() => {}), "function");

View File

@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal]
const instance = new Temporal.Instant(0n); const instance = new Temporal.Instant(0n);
const rangeErrorTests = [ const primitiveTests = [
[null, "null"], [null, "null"],
[true, "boolean"], [true, "boolean"],
["", "empty string"], ["", "empty string"],
@ -20,8 +20,12 @@ const rangeErrorTests = [
[1n, "bigint"], [1n, "bigint"],
]; ];
for (const [timeZone, description] of rangeErrorTests) { for (const [timeZone, description] of primitiveTests) {
assert.throws(RangeError, () => instance.toString({ timeZone }), `${description} does not convert to a valid ISO string`); assert.throws(
typeof timeZone === 'string' ? RangeError : TypeError,
() => instance.toString({ timeZone }),
`${description} does not convert to a valid ISO string`
);
} }
const typeErrorTests = [ const typeErrorTests = [

Some files were not shown because too many files have changed in this diff Show More