Tests disallowed smallest and largest unit arguments to PYM.since

This commit is contained in:
Sarah GHP 2021-11-16 19:48:53 +01:00 committed by Rick Waldron
parent 927ad3051f
commit 9c6ecf5326
2 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,24 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plainyearmonth.prototype.since
description: Since throws on to0-small largestUnit
features: [Temporal, arrow-function]
---*/
const earlier = new Temporal.PlainYearMonth(2019, 1);
const later = new Temporal.PlainYearMonth(2021, 9);
[
'weeks',
'days',
'hours',
'minutes',
'seconds',
'milliseconds',
'microseconds',
'nanoseconds'
].forEach((largestUnit) => {
assert.throws(RangeError, () => later.since(earlier, { largestUnit }),`throws on disallowed or invalid largestUnit: ${largestUnit}`);
});

View File

@ -0,0 +1,28 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plainyearmonth.prototype.since
description: Since throws on disallowed or invalid smallestUnit
features: [Temporal, arrow-function]
---*/
const earlier = new Temporal.PlainYearMonth(2019, 1);
const later = new Temporal.PlainYearMonth(2021, 9);
[
'era',
'weeks',
'days',
'hours',
'minutes',
'seconds',
'milliseconds',
'microseconds',
'nanoseconds',
'nonsense'
].forEach((smallestUnit) => {
assert.throws(RangeError, () => later.since(earlier, { smallestUnit }),`throws on disallowed or invalid smallestUnit: ${smallestUnit}`);
});
assert.throws(RangeError, () => later.since(earlier, { largestUnit: 'months', smallestUnit: 'years' }), 'throws if smallestUnit is larger than largestUnit');