mirror of
https://github.com/RGBCube/serenity
synced 2025-07-03 01:12:06 +00:00
test-js: Use prettier and format all files
This commit is contained in:
parent
e532888242
commit
6d58c48c2f
248 changed files with 8291 additions and 7725 deletions
|
@ -1,70 +1,74 @@
|
|||
describe("[[Has]] trap normal behavior", () => {
|
||||
test("forwarding when not defined in handler", () => {
|
||||
expect("foo" in new Proxy({}, { has: null })).toBeFalse();
|
||||
expect("foo" in new Proxy({}, { has: undefined})).toBeFalse();
|
||||
expect("foo" in new Proxy({}, {})).toBeFalse();
|
||||
test("forwarding when not defined in handler", () => {
|
||||
expect("foo" in new Proxy({}, { has: null })).toBeFalse();
|
||||
expect("foo" in new Proxy({}, { has: undefined })).toBeFalse();
|
||||
expect("foo" in new Proxy({}, {})).toBeFalse();
|
||||
});
|
||||
|
||||
test("correct arguments supplied to trap", () => {
|
||||
let o = {};
|
||||
let p = new Proxy(o, {
|
||||
has(target, prop) {
|
||||
expect(target).toBe(o);
|
||||
expect(prop).toBe("foo");
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
test("correct arguments supplied to trap", () => {
|
||||
let o = {};
|
||||
let p = new Proxy(o, {
|
||||
has(target, prop) {
|
||||
expect(target).toBe(o);
|
||||
expect(prop).toBe("foo");
|
||||
return true;
|
||||
}
|
||||
});
|
||||
"foo" in p;
|
||||
});
|
||||
|
||||
"foo" in p;
|
||||
test("conditional return", () => {
|
||||
let o = {};
|
||||
let p = new Proxy(o, {
|
||||
has(target, prop) {
|
||||
if (target.checkedFoo) return true;
|
||||
if (prop === "foo") target.checkedFoo = true;
|
||||
return false;
|
||||
},
|
||||
});
|
||||
|
||||
test("conditional return", () => {
|
||||
let o = {};
|
||||
let p = new Proxy(o, {
|
||||
has(target, prop) {
|
||||
if (target.checkedFoo)
|
||||
return true;
|
||||
if (prop === "foo")
|
||||
target.checkedFoo = true;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
expect("foo" in p).toBeFalse();
|
||||
expect("foo" in p).toBeTrue();
|
||||
});
|
||||
expect("foo" in p).toBeFalse();
|
||||
expect("foo" in p).toBeTrue();
|
||||
});
|
||||
});
|
||||
|
||||
describe("[[Has]] invariants", () => {
|
||||
test("cannot return false if the property exists and is non-configurable", () => {
|
||||
let o = {};
|
||||
Object.defineProperty(o, "foo", { configurable: false });
|
||||
test("cannot return false if the property exists and is non-configurable", () => {
|
||||
let o = {};
|
||||
Object.defineProperty(o, "foo", { configurable: false });
|
||||
|
||||
p = new Proxy(o, {
|
||||
has() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
expect(() => {
|
||||
"foo" in p;
|
||||
}).toThrowWithMessage(TypeError, "Proxy handler's has trap violates invariant: a property cannot be reported as non-existent if it exists on the target as a non-configurable property");
|
||||
p = new Proxy(o, {
|
||||
has() {
|
||||
return false;
|
||||
},
|
||||
});
|
||||
|
||||
test("cannot return false if the property exists and the target is non-extensible", () => {
|
||||
let o = {};
|
||||
Object.defineProperty(o, "foo", { value: 10, configurable: true });
|
||||
expect(() => {
|
||||
"foo" in p;
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
"Proxy handler's has trap violates invariant: a property cannot be reported as non-existent if it exists on the target as a non-configurable property"
|
||||
);
|
||||
});
|
||||
|
||||
let p = new Proxy(o, {
|
||||
has() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
test("cannot return false if the property exists and the target is non-extensible", () => {
|
||||
let o = {};
|
||||
Object.defineProperty(o, "foo", { value: 10, configurable: true });
|
||||
|
||||
Object.preventExtensions(o);
|
||||
|
||||
expect(() => {
|
||||
"foo" in p;
|
||||
}).toThrowWithMessage(TypeError, "Proxy handler's has trap violates invariant: a property cannot be reported as non-existent if it exists on the target and the target is non-extensible");
|
||||
let p = new Proxy(o, {
|
||||
has() {
|
||||
return false;
|
||||
},
|
||||
});
|
||||
|
||||
Object.preventExtensions(o);
|
||||
|
||||
expect(() => {
|
||||
"foo" in p;
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
"Proxy handler's has trap violates invariant: a property cannot be reported as non-existent if it exists on the target and the target is non-extensible"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue