WeakSet.js 896 B

123456789101112131415161718192021222324252627282930
  1. test("constructor properties", () => {
  2. expect(WeakSet).toHaveLength(0);
  3. expect(WeakSet.name).toBe("WeakSet");
  4. });
  5. describe("errors", () => {
  6. test("invalid array iterators", () => {
  7. [-100, Infinity, NaN, {}, 152n].forEach(value => {
  8. expect(() => {
  9. new WeakSet(value);
  10. }).toThrowWithMessage(TypeError, "is not iterable");
  11. });
  12. });
  13. test("called without new", () => {
  14. expect(() => {
  15. WeakSet();
  16. }).toThrowWithMessage(TypeError, "WeakSet constructor must be called with 'new'");
  17. });
  18. });
  19. describe("normal behavior", () => {
  20. test("typeof", () => {
  21. expect(typeof new WeakSet()).toBe("object");
  22. });
  23. test("constructor with single array argument", () => {
  24. var a = new WeakSet([{ a: 1 }, { a: 2 }, { a: 3 }]);
  25. expect(a instanceof WeakSet).toBeTrue();
  26. });
  27. });