123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353 |
- describe("errors", () => {
- test("structurally invalid tag", () => {
- expect(() => {
- new Intl.NumberFormat("root");
- }).toThrowWithMessage(RangeError, "root is not a structurally valid language tag");
- expect(() => {
- new Intl.NumberFormat("en-");
- }).toThrowWithMessage(RangeError, "en- is not a structurally valid language tag");
- expect(() => {
- new Intl.NumberFormat("Latn");
- }).toThrowWithMessage(RangeError, "Latn is not a structurally valid language tag");
- expect(() => {
- new Intl.NumberFormat("en-u-aa-U-aa");
- }).toThrowWithMessage(RangeError, "en-u-aa-U-aa is not a structurally valid language tag");
- });
- test("options is an invalid type", () => {
- expect(() => {
- new Intl.NumberFormat("en", null);
- }).toThrowWithMessage(TypeError, "ToObject on null or undefined");
- });
- test("localeMatcher option is invalid ", () => {
- expect(() => {
- new Intl.NumberFormat("en", { localeMatcher: "hello!" });
- }).toThrowWithMessage(RangeError, "hello! is not a valid value for option localeMatcher");
- });
- test("numberingSystem option is invalid ", () => {
- expect(() => {
- new Intl.NumberFormat("en", { numberingSystem: "hello!" });
- }).toThrowWithMessage(RangeError, "hello! is not a valid value for option numberingSystem");
- });
- test("style option is invalid ", () => {
- expect(() => {
- new Intl.NumberFormat("en", { style: "hello!" });
- }).toThrowWithMessage(RangeError, "hello! is not a valid value for option style");
- });
- test("currency option is undefined when required ", () => {
- expect(() => {
- new Intl.NumberFormat("en", { style: "currency" });
- }).toThrowWithMessage(
- TypeError,
- "Option currency must be defined when option style is currency"
- );
- });
- test("currency option is invalid ", () => {
- expect(() => {
- new Intl.NumberFormat("en", { currency: "hello!" });
- }).toThrowWithMessage(RangeError, "hello! is not a valid value for option currency");
- });
- test("currencyDisplay option is invalid ", () => {
- expect(() => {
- new Intl.NumberFormat("en", { currencyDisplay: "hello!" });
- }).toThrowWithMessage(RangeError, "hello! is not a valid value for option currencyDisplay");
- });
- test("currencySign option is invalid ", () => {
- expect(() => {
- new Intl.NumberFormat("en", { currencySign: "hello!" });
- }).toThrowWithMessage(RangeError, "hello! is not a valid value for option currencySign");
- });
- test("unit option is undefined when required ", () => {
- expect(() => {
- new Intl.NumberFormat("en", { style: "unit" });
- }).toThrowWithMessage(TypeError, "Option unit must be defined when option style is unit");
- });
- test("unit option is invalid ", () => {
- expect(() => {
- new Intl.NumberFormat("en", { unit: "hello!" });
- }).toThrowWithMessage(RangeError, "hello! is not a valid value for option unit");
- expect(() => {
- new Intl.NumberFormat("en", { unit: "acre-bit" });
- }).toThrowWithMessage(RangeError, "acre-bit is not a valid value for option unit");
- expect(() => {
- new Intl.NumberFormat("en", { unit: "acre-per-bit-per-byte" });
- }).toThrowWithMessage(
- RangeError,
- "acre-per-bit-per-byte is not a valid value for option unit"
- );
- });
- test("unitDisplay option is invalid ", () => {
- expect(() => {
- new Intl.NumberFormat("en", { unitDisplay: "hello!" });
- }).toThrowWithMessage(RangeError, "hello! is not a valid value for option unitDisplay");
- });
- test("notation option is invalid ", () => {
- expect(() => {
- new Intl.NumberFormat("en", { notation: "hello!" });
- }).toThrowWithMessage(RangeError, "hello! is not a valid value for option notation");
- });
- test("minimumIntegerDigits option is invalid ", () => {
- expect(() => {
- new Intl.NumberFormat("en", { minimumIntegerDigits: 1n });
- }).toThrowWithMessage(TypeError, "Cannot convert BigInt to number");
- expect(() => {
- new Intl.NumberFormat("en", { minimumIntegerDigits: "hello!" });
- }).toThrowWithMessage(RangeError, "Value NaN is NaN or is not between 1 and 21");
- expect(() => {
- new Intl.NumberFormat("en", { minimumIntegerDigits: 0 });
- }).toThrowWithMessage(RangeError, "Value 0 is NaN or is not between 1 and 21");
- expect(() => {
- new Intl.NumberFormat("en", { minimumIntegerDigits: 22 });
- }).toThrowWithMessage(RangeError, "Value 22 is NaN or is not between 1 and 21");
- });
- test("minimumFractionDigits option is invalid ", () => {
- expect(() => {
- new Intl.NumberFormat("en", { minimumFractionDigits: 1n });
- }).toThrowWithMessage(TypeError, "Cannot convert BigInt to number");
- expect(() => {
- new Intl.NumberFormat("en", { minimumFractionDigits: "hello!" });
- }).toThrowWithMessage(RangeError, "Value NaN is NaN or is not between 0 and 20");
- expect(() => {
- new Intl.NumberFormat("en", { minimumFractionDigits: -1 });
- }).toThrowWithMessage(RangeError, "Value -1 is NaN or is not between 0 and 20");
- expect(() => {
- new Intl.NumberFormat("en", { minimumFractionDigits: 21 });
- }).toThrowWithMessage(RangeError, "Value 21 is NaN or is not between 0 and 20");
- });
- test("maximumFractionDigits option is invalid ", () => {
- expect(() => {
- new Intl.NumberFormat("en", { maximumFractionDigits: 1n });
- }).toThrowWithMessage(TypeError, "Cannot convert BigInt to number");
- expect(() => {
- new Intl.NumberFormat("en", { maximumFractionDigits: "hello!" });
- }).toThrowWithMessage(RangeError, "Value NaN is NaN or is not between 0 and 20");
- expect(() => {
- new Intl.NumberFormat("en", { maximumFractionDigits: -1 });
- }).toThrowWithMessage(RangeError, "Value -1 is NaN or is not between 0 and 20");
- expect(() => {
- new Intl.NumberFormat("en", { maximumFractionDigits: 21 });
- }).toThrowWithMessage(RangeError, "Value 21 is NaN or is not between 0 and 20");
- expect(() => {
- new Intl.NumberFormat("en", { minimumFractionDigits: 10, maximumFractionDigits: 5 });
- }).toThrowWithMessage(RangeError, "Minimum value 10 is larger than maximum value 5");
- });
- test("minimumSignificantDigits option is invalid ", () => {
- expect(() => {
- new Intl.NumberFormat("en", { minimumSignificantDigits: 1n });
- }).toThrowWithMessage(TypeError, "Cannot convert BigInt to number");
- expect(() => {
- new Intl.NumberFormat("en", { minimumSignificantDigits: "hello!" });
- }).toThrowWithMessage(RangeError, "Value NaN is NaN or is not between 1 and 21");
- expect(() => {
- new Intl.NumberFormat("en", { minimumSignificantDigits: 0 });
- }).toThrowWithMessage(RangeError, "Value 0 is NaN or is not between 1 and 21");
- expect(() => {
- new Intl.NumberFormat("en", { minimumSignificantDigits: 22 });
- }).toThrowWithMessage(RangeError, "Value 22 is NaN or is not between 1 and 21");
- });
- test("maximumSignificantDigits option is invalid ", () => {
- expect(() => {
- new Intl.NumberFormat("en", { maximumSignificantDigits: 1n });
- }).toThrowWithMessage(TypeError, "Cannot convert BigInt to number");
- expect(() => {
- new Intl.NumberFormat("en", { maximumSignificantDigits: "hello!" });
- }).toThrowWithMessage(RangeError, "Value NaN is NaN or is not between 1 and 21");
- expect(() => {
- new Intl.NumberFormat("en", { maximumSignificantDigits: 0 });
- }).toThrowWithMessage(RangeError, "Value 0 is NaN or is not between 1 and 21");
- expect(() => {
- new Intl.NumberFormat("en", { maximumSignificantDigits: 22 });
- }).toThrowWithMessage(RangeError, "Value 22 is NaN or is not between 1 and 21");
- });
- test("compactDisplay option is invalid ", () => {
- expect(() => {
- new Intl.NumberFormat("en", { compactDisplay: "hello!" });
- }).toThrowWithMessage(RangeError, "hello! is not a valid value for option compactDisplay");
- });
- test("signDisplay option is invalid ", () => {
- expect(() => {
- new Intl.NumberFormat("en", { signDisplay: "hello!" });
- }).toThrowWithMessage(RangeError, "hello! is not a valid value for option signDisplay");
- });
- });
- describe("normal behavior", () => {
- test("length is 0", () => {
- expect(Intl.NumberFormat).toHaveLength(0);
- });
- test("all valid localeMatcher options", () => {
- ["lookup", "best fit"].forEach(localeMatcher => {
- expect(() => {
- new Intl.NumberFormat("en", { localeMatcher: localeMatcher });
- }).not.toThrow();
- });
- });
- test("valid numberingSystem options", () => {
- ["latn", "arab", "abc-def-ghi"].forEach(numberingSystem => {
- expect(() => {
- new Intl.NumberFormat("en", { numberingSystem: numberingSystem });
- }).not.toThrow();
- });
- });
- test("all valid style options", () => {
- ["decimal", "percent"].forEach(style => {
- expect(() => {
- new Intl.NumberFormat("en", { style: style });
- }).not.toThrow();
- });
- expect(() => {
- new Intl.NumberFormat("en", { style: "currency", currency: "USD" });
- }).not.toThrow();
- expect(() => {
- new Intl.NumberFormat("en", { style: "unit", unit: "degree" });
- }).not.toThrow();
- });
- test("valid currency options", () => {
- ["USD", "EUR", "XAG"].forEach(currency => {
- expect(() => {
- new Intl.NumberFormat("en", { currency: currency });
- }).not.toThrow();
- });
- });
- test("all valid currencyDisplay options", () => {
- ["code", "symbol", "narrowSymbol", "name"].forEach(currencyDisplay => {
- expect(() => {
- new Intl.NumberFormat("en", { currencyDisplay: currencyDisplay });
- }).not.toThrow();
- });
- });
- test("all valid currencySign options", () => {
- ["standard", "accounting"].forEach(currencySign => {
- expect(() => {
- new Intl.NumberFormat("en", { currencySign: currencySign });
- }).not.toThrow();
- });
- });
- test("valid unit options", () => {
- ["acre", "acre-per-bit"].forEach(unit => {
- expect(() => {
- new Intl.NumberFormat("en", { unit: unit });
- }).not.toThrow();
- });
- });
- test("all valid unitDisplay options", () => {
- ["short", "narrow", "long"].forEach(unitDisplay => {
- expect(() => {
- new Intl.NumberFormat("en", { unitDisplay: unitDisplay });
- }).not.toThrow();
- });
- });
- test("all valid notation options", () => {
- ["standard", "scientific", "engineering", "compact"].forEach(notation => {
- expect(() => {
- new Intl.NumberFormat("en", { notation: notation });
- }).not.toThrow();
- });
- });
- test("all valid minimumIntegerDigits options", () => {
- for (let i = 1; i <= 21; ++i) {
- expect(() => {
- new Intl.NumberFormat("en", { minimumIntegerDigits: i });
- }).not.toThrow();
- }
- });
- test("all valid minimumFractionDigits options", () => {
- for (let i = 0; i <= 20; ++i) {
- expect(() => {
- new Intl.NumberFormat("en", { minimumFractionDigits: i });
- }).not.toThrow();
- }
- });
- test("all valid maximumFractionDigits options", () => {
- for (let i = 0; i <= 20; ++i) {
- expect(() => {
- new Intl.NumberFormat("en", { maximumFractionDigits: i });
- }).not.toThrow();
- }
- });
- test("all valid minimumSignificantDigits options", () => {
- for (let i = 1; i <= 21; ++i) {
- expect(() => {
- new Intl.NumberFormat("en", { minimumSignificantDigits: i });
- }).not.toThrow();
- }
- });
- test("all valid maximumSignificantDigits options", () => {
- for (let i = 1; i <= 21; ++i) {
- expect(() => {
- new Intl.NumberFormat("en", { maximumSignificantDigits: i });
- }).not.toThrow();
- }
- });
- test("all valid compactDisplay options", () => {
- ["short", "long"].forEach(compactDisplay => {
- expect(() => {
- new Intl.NumberFormat("en", { compactDisplay: compactDisplay });
- }).not.toThrow();
- });
- });
- test("all valid signDisplay options", () => {
- ["auto", "never", "always", "exceptZero"].forEach(signDisplay => {
- expect(() => {
- new Intl.NumberFormat("en", { signDisplay: signDisplay });
- }).not.toThrow();
- });
- });
- });
|