summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/RelativeTimeFormat/prototype/formatToParts/unit-invalid.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/intl402/RelativeTimeFormat/prototype/formatToParts/unit-invalid.js')
-rw-r--r--js/src/tests/test262/intl402/RelativeTimeFormat/prototype/formatToParts/unit-invalid.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/RelativeTimeFormat/prototype/formatToParts/unit-invalid.js b/js/src/tests/test262/intl402/RelativeTimeFormat/prototype/formatToParts/unit-invalid.js
new file mode 100644
index 0000000000..94e4355e09
--- /dev/null
+++ b/js/src/tests/test262/intl402/RelativeTimeFormat/prototype/formatToParts/unit-invalid.js
@@ -0,0 +1,55 @@
+// 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",
+ "decade",
+ "decades",
+ "century",
+ "centuries",
+ "millisecond",
+ "milliseconds",
+ "microsecond",
+ "microseconds",
+ "nanosecond",
+ "nanoseconds",
+];
+
+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");
+
+reportCompare(0, 0);