WeakMap.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. test("constructor properties", () => {
  2. expect(WeakMap).toHaveLength(0);
  3. expect(WeakMap.name).toBe("WeakMap");
  4. });
  5. describe("errors", () => {
  6. test("invalid array iterators", () => {
  7. [-100, Infinity, NaN, {}, 152n].forEach(value => {
  8. expect(() => {
  9. new WeakMap(value);
  10. }).toThrowWithMessage(TypeError, "is not iterable");
  11. });
  12. });
  13. test("called without new", () => {
  14. expect(() => {
  15. WeakMap();
  16. }).toThrowWithMessage(TypeError, "WeakMap constructor must be called with 'new'");
  17. });
  18. });
  19. describe("normal behavior", () => {
  20. test("typeof", () => {
  21. expect(typeof new WeakMap()).toBe("object");
  22. });
  23. test("constructor with single array of entries argument", () => {
  24. var a = new WeakMap([
  25. [{ a: 1 }, 1],
  26. [{ a: 2 }, 2],
  27. [{ a: 3 }, 3],
  28. ]);
  29. expect(a instanceof WeakMap).toBeTrue();
  30. });
  31. });
  32. describe("regressions", () => {
  33. test("missing key/value properties on iterable entry", () => {
  34. expect(() => {
  35. new WeakMap([{}]);
  36. }).toThrowWithMessage(TypeError, "undefined is not an object");
  37. });
  38. });