Reflect.preventExtensions.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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(
  7. TypeError,
  8. "First argument of Reflect.preventExtensions() must be an object"
  9. );
  10. });
  11. });
  12. });
  13. describe("normal behavior", () => {
  14. test("length is 1", () => {
  15. expect(Reflect.preventExtensions).toHaveLength(1);
  16. });
  17. test("properties cannot be added", () => {
  18. var o = {};
  19. o.foo = "foo";
  20. expect(Reflect.preventExtensions(o)).toBeTrue();
  21. o.bar = "bar";
  22. expect(o.foo).toBe("foo");
  23. expect(o.bar).toBeUndefined();
  24. });
  25. test("modifying existing properties", () => {
  26. const o = {};
  27. o.foo = "foo";
  28. expect(Reflect.preventExtensions(o)).toBeTrue();
  29. o.foo = "bar";
  30. expect(o.foo).toBe("bar");
  31. });
  32. test("deleting existing properties", () => {
  33. const o = { foo: "bar" };
  34. Reflect.preventExtensions(o);
  35. delete o.foo;
  36. expect(o).not.toHaveProperty("foo");
  37. });
  38. });