Reflect.preventExtensions.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. describe("errors", () => {
  2. test("target must be an object", () => {
  3. [null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
  4. expect(() => {
  5. Reflect.preventExtensions(value);
  6. }).toThrowWithMessage(TypeError, `${value} is not an object`);
  7. });
  8. });
  9. });
  10. describe("normal behavior", () => {
  11. test("length is 1", () => {
  12. expect(Reflect.preventExtensions).toHaveLength(1);
  13. });
  14. test("properties cannot be added", () => {
  15. var o = {};
  16. o.foo = "foo";
  17. expect(Reflect.preventExtensions(o)).toBeTrue();
  18. o.bar = "bar";
  19. expect(o.foo).toBe("foo");
  20. expect(o.bar).toBeUndefined();
  21. });
  22. test("modifying existing properties", () => {
  23. const o = {};
  24. o.foo = "foo";
  25. expect(Reflect.preventExtensions(o)).toBeTrue();
  26. o.foo = "bar";
  27. expect(o.foo).toBe("bar");
  28. });
  29. test("deleting existing properties", () => {
  30. const o = { foo: "bar" };
  31. Reflect.preventExtensions(o);
  32. delete o.foo;
  33. expect(o).not.toHaveProperty("foo");
  34. });
  35. });