DisplayNames.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. describe("errors", () => {
  2. test("called without new", () => {
  3. expect(() => {
  4. Intl.DisplayNames();
  5. }).toThrowWithMessage(TypeError, "Intl.DisplayNames constructor must be called with 'new'");
  6. });
  7. test("options is undefined", () => {
  8. expect(() => {
  9. new Intl.DisplayNames("en");
  10. }).toThrowWithMessage(TypeError, "options is undefined");
  11. });
  12. test("options is an invalid type", () => {
  13. expect(() => {
  14. new Intl.DisplayNames("en", true);
  15. }).toThrowWithMessage(TypeError, "Options is not an object");
  16. });
  17. test("style option is invalid ", () => {
  18. expect(() => {
  19. new Intl.DisplayNames("en", { style: "hello!" });
  20. }).toThrowWithMessage(RangeError, "hello! is not a valid value for option style");
  21. });
  22. test("type option is invalid ", () => {
  23. expect(() => {
  24. new Intl.DisplayNames("en", { type: "hello!" });
  25. }).toThrowWithMessage(RangeError, "hello! is not a valid value for option type");
  26. });
  27. test("fallback option is invalid ", () => {
  28. expect(() => {
  29. new Intl.DisplayNames("en", { type: "region", fallback: "hello!" });
  30. }).toThrowWithMessage(RangeError, "hello! is not a valid value for option fallback");
  31. });
  32. test("language display option is invalid ", () => {
  33. expect(() => {
  34. new Intl.DisplayNames("en", { type: "language", languageDisplay: "hello!" });
  35. }).toThrowWithMessage(RangeError, "hello! is not a valid value for option languageDisplay");
  36. });
  37. test("missing type options ", () => {
  38. expect(() => {
  39. new Intl.DisplayNames("en", {});
  40. }).toThrowWithMessage(TypeError, "options.type is undefined");
  41. });
  42. });
  43. describe("normal behavior", () => {
  44. test("length is 2", () => {
  45. expect(Intl.DisplayNames).toHaveLength(2);
  46. });
  47. test("all valid types", () => {
  48. ["language", "region", "script", "currency", "calendar", "dateTimeField"].forEach(type => {
  49. expect(() => {
  50. new Intl.DisplayNames("en", { type: type });
  51. }).not.toThrow();
  52. });
  53. });
  54. test("all valid language displays", () => {
  55. ["dialect", "standard"].forEach(languageDisplay => {
  56. expect(() => {
  57. new Intl.DisplayNames("en", { type: "language", languageDisplay: languageDisplay });
  58. }).not.toThrow();
  59. });
  60. });
  61. });