DisplayNames.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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("missing type options ", () => {
  33. expect(() => {
  34. new Intl.DisplayNames("en", {});
  35. }).toThrowWithMessage(TypeError, "options.type is undefined");
  36. });
  37. });
  38. describe("normal behavior", () => {
  39. test("length is 2", () => {
  40. expect(Intl.DisplayNames).toHaveLength(2);
  41. });
  42. test("all valid types", () => {
  43. ["language", "region", "script", "currency"].forEach(type => {
  44. expect(() => {
  45. new Intl.DisplayNames("en", { type: type });
  46. }).not.toThrow();
  47. });
  48. });
  49. });