summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/RelativeTimeFormat/prototype/format/unit-invalid.js
blob: 186ff57ec9f35fa27f07bcfef27a9d311ce6aa22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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.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",
  "decade",
  "decades",
  "century",
  "centuries",
  "millisecond",
  "milliseconds",
  "microsecond",
  "microseconds",
  "nanosecond",
  "nanoseconds",
];

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");

reportCompare(0, 0);