Set.js 872 B

12345678910111213141516171819202122232425262728293031
  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. });
  28. });