Add tests for wrong argument type in Temporal.TimeZone

This commit is contained in:
Aditi 2022-07-28 18:04:58 +05:30 committed by Philip Chimento
parent e48df0b964
commit b37d74191a
4 changed files with 148 additions and 0 deletions

View File

@ -0,0 +1,37 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.timezone.prototype.getnexttransition
description: >
Appropriate error thrown when argument cannot be converted to a valid string
for Instant
features: [BigInt, Symbol, Temporal]
---*/
const instance = new Temporal.TimeZone("UTC");
const rangeErrorTests = [
[undefined, "undefined"],
[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"],
[{}, "plain object"],
[Temporal.Instant, "Temporal.Instant, object"],
];
for (const [arg, description] of rangeErrorTests) {
assert.throws(RangeError, () => instance.getNextTransition(arg), `${description} does not convert to a valid ISO string`);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[Temporal.Instant.prototype, "Temporal.Instant.prototype, object"], // fails brand check in toString()
];
for (const [arg, description] of typeErrorTests) {
assert.throws(TypeError, () => instance.getNextTransition(arg), `${description} does not convert to a string`);
}

View File

@ -0,0 +1,37 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.timezone.prototype.getoffsetnanosecondsfor
description: >
Appropriate error thrown when argument cannot be converted to a valid string
for Instant
features: [BigInt, Symbol, Temporal]
---*/
const instance = new Temporal.TimeZone("UTC");
const rangeErrorTests = [
[undefined, "undefined"],
[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"],
[{}, "plain object"],
[Temporal.Instant, "Temporal.Instant, object"],
];
for (const [arg, description] of rangeErrorTests) {
assert.throws(RangeError, () => instance.getOffsetNanosecondsFor(arg), `${description} does not convert to a valid ISO string`);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[Temporal.Instant.prototype, "Temporal.Instant.prototype, object"], // fails brand check in toString()
];
for (const [arg, description] of typeErrorTests) {
assert.throws(TypeError, () => instance.getOffsetNanosecondsFor(arg), `${description} does not convert to a string`);
}

View File

@ -0,0 +1,37 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.timezone.prototype.getoffsetstringfor
description: >
Appropriate error thrown when argument cannot be converted to a valid string
for Instant
features: [BigInt, Symbol, Temporal]
---*/
const instance = new Temporal.TimeZone("UTC");
const rangeErrorTests = [
[undefined, "undefined"],
[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"],
[{}, "plain object"],
[Temporal.Instant, "Temporal.Instant, object"],
];
for (const [arg, description] of rangeErrorTests) {
assert.throws(RangeError, () => instance.getOffsetStringFor(arg), `${description} does not convert to a valid ISO string`);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[Temporal.Instant.prototype, "Temporal.Instant.prototype, object"], // fails brand check in toString()
];
for (const [arg, description] of typeErrorTests) {
assert.throws(TypeError, () => instance.getOffsetStringFor(arg), `${description} does not convert to a string`);
}

View File

@ -0,0 +1,37 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.timezone.prototype.getprevioustransition
description: >
Appropriate error thrown when argument cannot be converted to a valid string
for Instant
features: [BigInt, Symbol, Temporal]
---*/
const instance = new Temporal.TimeZone("UTC");
const rangeErrorTests = [
[undefined, "undefined"],
[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"],
[{}, "plain object"],
[Temporal.Instant, "Temporal.Instant, object"],
];
for (const [arg, description] of rangeErrorTests) {
assert.throws(RangeError, () => instance.getPreviousTransition(arg), `${description} does not convert to a valid ISO string`);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[Temporal.Instant.prototype, "Temporal.Instant.prototype, object"], // fails brand check in toString()
];
for (const [arg, description] of typeErrorTests) {
assert.throws(TypeError, () => instance.getPreviousTransition(arg), `${description} does not convert to a string`);
}