Intl.supportedValuesOf.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. describe("errors", () => {
  2. test("invalid key", () => {
  3. expect(() => {
  4. Intl.supportedValuesOf("hello!");
  5. }).toThrowWithMessage(RangeError, "hello! is not a valid key");
  6. });
  7. });
  8. describe("normal behavior", () => {
  9. const isSorted = array => {
  10. return array.slice(1).every((item, i) => array[i] <= item);
  11. };
  12. test("length is 1", () => {
  13. expect(Intl.supportedValuesOf).toHaveLength(1);
  14. });
  15. test("calendar", () => {
  16. const values = Intl.supportedValuesOf("calendar");
  17. expect(isSorted(values)).toBeTrue();
  18. expect(values.indexOf("gregory")).not.toBe(-1);
  19. });
  20. test("collation", () => {
  21. const values = Intl.supportedValuesOf("collation");
  22. expect(isSorted(values)).toBeTrue();
  23. expect(values.indexOf("default")).not.toBe(-1);
  24. });
  25. test("currency", () => {
  26. const values = Intl.supportedValuesOf("currency");
  27. expect(isSorted(values)).toBeTrue();
  28. expect(values.indexOf("USD")).not.toBe(-1);
  29. expect(values.indexOf("XXX")).not.toBe(-1);
  30. });
  31. test("numberingSystem", () => {
  32. const values = Intl.supportedValuesOf("numberingSystem");
  33. expect(isSorted(values)).toBeTrue();
  34. expect(values.indexOf("latn")).not.toBe(-1);
  35. expect(values.indexOf("arab")).not.toBe(-1);
  36. });
  37. test("timeZone", () => {
  38. const values = Intl.supportedValuesOf("timeZone");
  39. expect(isSorted(values)).toBeTrue();
  40. expect(values.indexOf("UTC")).not.toBe(-1);
  41. expect(values.indexOf("America/New_York")).not.toBe(-1);
  42. });
  43. test("unit", () => {
  44. const values = Intl.supportedValuesOf("unit");
  45. expect(isSorted(values)).toBeTrue();
  46. expect(values.indexOf("acre")).not.toBe(-1);
  47. expect(values.indexOf("fluid-ounce")).not.toBe(-1);
  48. });
  49. });