Map.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. test("constructor properties", () => {
  2. expect(Map).toHaveLength(0);
  3. expect(Map.name).toBe("Map");
  4. });
  5. describe("errors", () => {
  6. test("invalid array iterators", () => {
  7. [-100, Infinity, NaN, {}, 152n].forEach(value => {
  8. expect(() => {
  9. new Map(value);
  10. }).toThrowWithMessage(TypeError, "is not iterable");
  11. });
  12. });
  13. test("invalid iterator entries", () => {
  14. expect(() => {
  15. new Map([1, 2, 3]);
  16. }).toThrowWithMessage(TypeError, "Iterator value 1 is not an object");
  17. });
  18. test("called without new", () => {
  19. expect(() => {
  20. Map();
  21. }).toThrowWithMessage(TypeError, "Map constructor must be called with 'new'");
  22. });
  23. });
  24. describe("normal behavior", () => {
  25. test("typeof", () => {
  26. expect(typeof new Map()).toBe("object");
  27. });
  28. test("constructor with single entries array argument", () => {
  29. var a = new Map([
  30. ["a", 0],
  31. ["b", 1],
  32. ["c", 2],
  33. ]);
  34. expect(a instanceof Map).toBeTrue();
  35. expect(a).toHaveSize(3);
  36. var seen = [false, false, false];
  37. a.forEach(v => {
  38. seen[v] = true;
  39. });
  40. expect(seen[0] && seen[1] && seen[2]);
  41. });
  42. });