Updated expected error in NumberFormat constructor per current spec

This commit is contained in:
André Bargull 2020-06-24 03:25:15 -07:00 committed by Rick Waldron
parent d42aaa4b15
commit 630f7dee66
2 changed files with 20 additions and 8 deletions

View File

@ -10,17 +10,16 @@ info: |
5. Let currency be ? GetOption(options, "currency", "string", undefined, undefined).
6. If currency is not undefined, then
a. If the result of IsWellFormedCurrencyCode(currency) is false, throw a RangeError exception.
9. Let unit be ? GetOption(options, "unit", "string", undefined, undefined).
10. If unit is not undefined, then
7. If style is "currency" and currency is undefined, throw a TypeError exception.
...
10. Let unit be ? GetOption(options, "unit", "string", undefined, undefined).
11. If unit is not undefined, then
a. If the result of IsWellFormedUnitIdentifier(unit) is false, throw a RangeError exception.
12. If style is "currency", then
a. If currency is undefined, throw a TypeError exception.
13. If style is "unit", then
a. If unit is undefined, throw a TypeError exception.
12. If style is "unit" and unit is undefined, throw a TypeError exception.
features: [Intl.NumberFormat-unified]
---*/
assert.throws(RangeError, () => {
assert.throws(TypeError, () => {
new Intl.NumberFormat([], { style: "currency", unit: "test" })
});

View File

@ -14,11 +14,24 @@ assert.throws(TypeError, () => {
});
for (const unit of ["test", "MILE", "kB"]) {
for (const style of [undefined, "decimal", "currency", "unit"]) {
// Throws RangeError for invalid unit identifier.
for (const style of [undefined, "decimal", "unit"]) {
assert.throws(RangeError, () => {
new Intl.NumberFormat([], { style, unit })
}, `{ style: ${style}, unit: ${unit} }`);
}
const style = "currency";
// Throws TypeError because "currency" option is missing.
assert.throws(TypeError, () => {
new Intl.NumberFormat([], { style, unit })
}, `{ style: ${style}, unit: ${unit} }`);
// Throws RangeError for invalid unit identifier.
assert.throws(RangeError, () => {
new Intl.NumberFormat([], { style, unit, currency: "USD" })
}, `{ style: ${style}, unit: ${unit} }`);
}
const nf = new Intl.NumberFormat([], {