2020-07-05 21:26:26 -03:00
|
|
|
test("class properties", () => {
|
2020-07-06 11:37:45 -03:00
|
|
|
class A {}
|
|
|
|
|
expect(A.name).toBe("A");
|
|
|
|
|
expect(A).toHaveLength(0);
|
2020-07-05 21:26:26 -03:00
|
|
|
});
|
2026-05-21 08:10:51 -03:00
|
|
|
|
|
|
|
|
test("class constructor prototype property descriptor", () => {
|
|
|
|
|
class A {}
|
|
|
|
|
|
|
|
|
|
const descriptor = Object.getOwnPropertyDescriptor(A, "prototype");
|
|
|
|
|
expect(descriptor.value).toBe(A.prototype);
|
|
|
|
|
expect(descriptor.writable).toBeFalse();
|
|
|
|
|
expect(descriptor.enumerable).toBeFalse();
|
|
|
|
|
expect(descriptor.configurable).toBeFalse();
|
|
|
|
|
|
|
|
|
|
const constructorDescriptor = Object.getOwnPropertyDescriptor(A.prototype, "constructor");
|
|
|
|
|
expect(constructorDescriptor.value).toBe(A);
|
|
|
|
|
expect(constructorDescriptor.writable).toBeTrue();
|
|
|
|
|
expect(constructorDescriptor.enumerable).toBeFalse();
|
|
|
|
|
expect(constructorDescriptor.configurable).toBeTrue();
|
|
|
|
|
});
|
2026-05-21 09:26:23 -03:00
|
|
|
|
|
|
|
|
test("class heritage and computed property names are strict mode code", () => {
|
|
|
|
|
expect(() => {
|
|
|
|
|
class A {
|
|
|
|
|
[(Object.preventExtensions({}).prop = 1)]() {}
|
|
|
|
|
}
|
|
|
|
|
}).toThrow(TypeError);
|
|
|
|
|
|
|
|
|
|
expect(() => {
|
|
|
|
|
const A = class {
|
|
|
|
|
[(Object.preventExtensions({}).prop = 1)]() {}
|
|
|
|
|
};
|
|
|
|
|
}).toThrow(TypeError);
|
|
|
|
|
|
|
|
|
|
expect(() => {
|
|
|
|
|
class A {
|
|
|
|
|
[(Object.preventExtensions({}).prop = 1)];
|
|
|
|
|
}
|
|
|
|
|
}).toThrow(TypeError);
|
|
|
|
|
|
|
|
|
|
expect(() => {
|
|
|
|
|
class A extends (Object.preventExtensions({}).prop = 1) {}
|
|
|
|
|
}).toThrow(TypeError);
|
|
|
|
|
|
|
|
|
|
expect(() => {
|
|
|
|
|
const A = class extends (Object.preventExtensions({}).prop = 1) {};
|
|
|
|
|
}).toThrow(TypeError);
|
|
|
|
|
});
|