Skip to content
Snippets Groups Projects
Commit 764eb4f8 authored by Ms2ger's avatar Ms2ger Committed by Rick Waldron
Browse files

Intl.RelativeTimeFormat: Add tests for invalid units in format/formatToParts.

parent 56e0ef70
No related branches found
No related tags found
No related merge requests found
// Copyright 2018 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-Intl.RelativeTimeFormat.prototype.format
description: Checks the handling of invalid unit arguments to Intl.RelativeTimeFormat.prototype.format().
info: |
SingularRelativeTimeUnit ( unit )
10. If unit is not one of "second", "minute", "hour", "day", "week", "month", "quarter", "year", throw a RangeError exception.
features: [Intl.RelativeTimeFormat]
---*/
const rtf = new Intl.RelativeTimeFormat("en-US");
assert.sameValue(typeof rtf.format, "function");
const values = [
undefined,
null,
true,
1,
0.1,
NaN,
{},
"",
"SECOND",
"MINUTE",
"HOUR",
"DAY",
"WEEK",
"MONTH",
"QUARTER",
"YEAR",
];
for (const value of values) {
assert.throws(RangeError, () => rtf.format(0, value), String(value));
}
const symbol = Symbol();
assert.throws(TypeError, () => rtf.format(0, symbol), "symbol");
// Copyright 2018 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-Intl.RelativeTimeFormat.prototype.formatToParts
description: Checks the handling of invalid unit arguments to Intl.RelativeTimeFormat.prototype.formatToParts().
info: |
SingularRelativeTimeUnit ( unit )
10. If unit is not one of "second", "minute", "hour", "day", "week", "month", "quarter", "year", throw a RangeError exception.
features: [Intl.RelativeTimeFormat]
---*/
const rtf = new Intl.RelativeTimeFormat("en-US");
assert.sameValue(typeof rtf.formatToParts, "function");
const values = [
undefined,
null,
true,
1,
0.1,
NaN,
{},
"",
"SECOND",
"MINUTE",
"HOUR",
"DAY",
"WEEK",
"MONTH",
"QUARTER",
"YEAR",
];
for (const value of values) {
assert.throws(RangeError, () => rtf.formatToParts(0, value), String(value));
}
const symbol = Symbol();
assert.throws(TypeError, () => rtf.formatToParts(0, symbol), "symbol");
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment