Set.js 1.0 KB

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