summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-defineProperty.js30
-rw-r--r--Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-deleteProperty.js10
-rw-r--r--Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-getOwnPropertyDescriptor.js26
-rw-r--r--Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-has.js10
-rw-r--r--Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-isExtensible.js8
-rw-r--r--Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-setPrototypeOf.js2
-rw-r--r--Libraries/LibJS/Tests/test-common-tests.js86
-rw-r--r--Libraries/LibJS/Tests/test-common.js74
8 files changed, 200 insertions, 46 deletions
diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-defineProperty.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-defineProperty.js
index f7312f06eb..c09338c457 100644
--- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-defineProperty.js
+++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-defineProperty.js
@@ -14,9 +14,9 @@ describe("[[DefineProperty]] trap normal behavior", () => {
defineProperty(target, name, descriptor) {
expect(target).toBe(o);
expect(name).toBe("foo");
- expect(descriptor.configurable).toBe(true);
+ expect(descriptor.configurable).toBeTrue();
expect(descriptor.enumerable).toBeUndefined();
- expect(descriptor.writable).toBe(true);
+ expect(descriptor.writable).toBeTrue();
expect(descriptor.value).toBe(10);
expect(descriptor.get).toBeUndefined();
expect(descriptor.set).toBeUndefined();
@@ -38,22 +38,20 @@ describe("[[DefineProperty]] trap normal behavior", () => {
});
Object.defineProperty(p, "foo", { value: 10, enumerable: true, configurable: false, writable: true });
- let d = Object.getOwnPropertyDescriptor(p, "foo");
- expect(d.enumerable).toBe(true);
- expect(d.configurable).toBe(false);
- expect(d.writable).toBe(true);
- expect(d.value).toBe(10);
- expect(d.get).toBeUndefined();
- expect(d.set).toBeUndefined();
+ expect(p).toHaveEnumerableProperty("foo");
+ expect(p).not.toHaveConfigurableProperty("foo");
+ expect(p).toHaveWritableProperty("foo");
+ expect(p).toHaveValueProperty("foo", 10);
+ expect(p).not.toHaveGetterProperty("foo");
+ expect(p).not.toHaveSetterProperty("foo");
Object.defineProperty(p, "foo", { value: 20, enumerable: true, configurable: false, writable: true });
- d = Object.getOwnPropertyDescriptor(p, "foo");
- expect(d.enumerable).toBe(true);
- expect(d.configurable).toBe(false);
- expect(d.writable).toBe(true);
- expect(d.value).toBe(10);
- expect(d.get).toBeUndefined();
- expect(d.set).toBeUndefined();
+ expect(p).toHaveEnumerableProperty("foo");
+ expect(p).not.toHaveConfigurableProperty("foo");
+ expect(p).toHaveWritableProperty("foo");
+ expect(p).toHaveValueProperty("foo", 10);
+ expect(p).not.toHaveGetterProperty("foo");
+ expect(p).not.toHaveSetterProperty("foo");
});
});
diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-deleteProperty.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-deleteProperty.js
index 1bd359624a..8e8f445059 100644
--- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-deleteProperty.js
+++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-deleteProperty.js
@@ -1,8 +1,8 @@
describe("[[Delete]] trap normal behavior", () => {
test("forwarding when not defined in handler", () => {
- expect(delete (new Proxy({}, { deleteProperty: undefined })).foo).toBe(true);
- expect(delete (new Proxy({}, { deleteProperty: null })).foo).toBe(true);
- expect(delete (new Proxy({}, {})).foo).toBe(true);
+ expect(delete (new Proxy({}, { deleteProperty: undefined })).foo).toBeTrue();
+ expect(delete (new Proxy({}, { deleteProperty: null })).foo).toBeTrue();
+ expect(delete (new Proxy({}, {})).foo).toBeTrue();
});
test("correct arguments supplied to trap", () => {
@@ -30,8 +30,8 @@ describe("[[Delete]] trap normal behavior", () => {
}
});
- expect(delete p.foo).toBe(true);
- expect(delete p.bar).toBe(false);
+ expect(delete p.foo).toBeTrue();
+ expect(delete p.bar).toBeFalse();
expect(o.foo).toBe(undefined);
expect(o.bar).toBe(2);
diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-getOwnPropertyDescriptor.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-getOwnPropertyDescriptor.js
index f077ec43c1..c32042fd26 100644
--- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-getOwnPropertyDescriptor.js
+++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-getOwnPropertyDescriptor.js
@@ -29,21 +29,21 @@ describe("[Call][GetOwnProperty]] trap normal behavior", () => {
}
});
- let d = Object.getOwnPropertyDescriptor(p, "baz");
- expect(d.configurable).toBe(true);
- expect(d.enumerable).toBe(false);
- expect(d.writable).toBe(false);
- expect(d.value).toBe("qux");
- expect(d.get).toBeUndefined();
- expect(d.set).toBeUndefined();
+ expect(p).toHaveConfigurableProperty("baz");
+ expect(p).not.toHaveEnumerableProperty("baz");
+ expect(p).not.toHaveWritableProperty("baz");
+ expect(p).toHaveValueProperty("baz", "qux");
+ expect(p).not.toHaveGetterProperty("baz");
+ expect(p).not.toHaveSetterProperty("baz");
d = Object.getOwnPropertyDescriptor(p, "foo");
- expect(d.configurable).toBe(true);
- expect(d.enumerable).toBe(false);
- expect(d.writable).toBe(true);
- expect(d.value).toBe("bar");
- expect(d.get).toBeUndefined();
- expect(d.set).toBeUndefined();
+
+ expect(p).toHaveConfigurableProperty("foo");
+ expect(p).not.toHaveEnumerableProperty("foo");
+ expect(p).toHaveWritableProperty("foo");
+ expect(p).toHaveValueProperty("foo", "bar");
+ expect(p).not.toHaveGetterProperty("foo");
+ expect(p).not.toHaveSetterProperty("foo");
});
});
diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-has.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-has.js
index aa1f965ce4..0d231f7436 100644
--- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-has.js
+++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-has.js
@@ -1,8 +1,8 @@
describe("[[Has]] trap normal behavior", () => {
test("forwarding when not defined in handler", () => {
- expect("foo" in new Proxy({}, { has: null })).toBe(false);
- expect("foo" in new Proxy({}, { has: undefined})).toBe(false);
- expect("foo" in new Proxy({}, {})).toBe(false);
+ 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", () => {
@@ -30,8 +30,8 @@ describe("[[Has]] trap normal behavior", () => {
}
});
- expect("foo" in p).toBe(false);
- expect("foo" in p).toBe(true);
+ expect("foo" in p).toBeFalse();
+ expect("foo" in p).toBeTrue();
});
});
diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-isExtensible.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-isExtensible.js
index fd92597857..89f15a3b1a 100644
--- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-isExtensible.js
+++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-isExtensible.js
@@ -1,8 +1,8 @@
describe("[[IsExtensible]] trap normal behavior", () => {
test("forwarding when not defined in handler", () => {
- expect(Object.isExtensible(new Proxy({}, { isExtensible: null }))).toBe(true);
- expect(Object.isExtensible(new Proxy({}, { isExtensible: undefined }))).toBe(true);
- expect(Object.isExtensible(new Proxy({}, {}))).toBe(true);
+ expect(Object.isExtensible(new Proxy({}, { isExtensible: null }))).toBeTrue();
+ expect(Object.isExtensible(new Proxy({}, { isExtensible: undefined }))).toBeTrue();
+ expect(Object.isExtensible(new Proxy({}, {}))).toBeTrue();
});
test("correct arguments supplied to trap", () => {
@@ -14,7 +14,7 @@ describe("[[IsExtensible]] trap normal behavior", () => {
}
});
- expect(Object.isExtensible(p)).toBe(true);
+ expect(Object.isExtensible(p)).toBeTrue();
});
});
diff --git a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-setPrototypeOf.js b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-setPrototypeOf.js
index 580cccaa3d..91d4d83075 100644
--- a/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-setPrototypeOf.js
+++ b/Libraries/LibJS/Tests/builtins/Proxy/Proxy.handler-setPrototypeOf.js
@@ -41,7 +41,7 @@ describe("[[SetPrototypeOf]] trap normal behavior", () => {
Object.setPrototypeOf(p, { foo: 1 });
expect(Object.getPrototypeOf(p).foo).toBeUndefined();
p.shouldSet = true;
- expect(o.shouldSet).toBe(true);
+ expect(o.shouldSet).toBeTrue();
Object.setPrototypeOf(p, { foo: 1 });
expect(Object.getPrototypeOf(p).foo).toBe(1);
});
diff --git a/Libraries/LibJS/Tests/test-common-tests.js b/Libraries/LibJS/Tests/test-common-tests.js
index 80089515a3..15be575b21 100644
--- a/Libraries/LibJS/Tests/test-common-tests.js
+++ b/Libraries/LibJS/Tests/test-common-tests.js
@@ -9,8 +9,8 @@ test("toBe", () => {
expect("1").toBe("1");
expect("1").not.toBe("2");
- expect(true).toBe(true);
- expect(true).not.toBe(false);
+ expect(true).toBeTrue();
+ expect(true).not.toBeFalse();
expect({}).not.toBe({});
expect([]).not.toBe([]);
@@ -100,6 +100,22 @@ test("toBeNaN", () => {
expect(5).not.toBeNaN();
});
+test("toBeTrue", () => {
+ expect(true).toBeTrue();
+ expect(false).not.toBeTrue();
+ expect(null).not.toBeTrue();
+ expect(undefined).not.toBeTrue();
+ expect(0).not.toBeTrue();
+});
+
+test("toBeFalse", () => {
+ expect(true).not.toBeFalse();
+ expect(false).toBeFalse();
+ expect(null).not.toBeFalse();
+ expect(undefined).not.toBeFalse();
+ expect(0).not.toBeFalse();
+});
+
test("toContain", () => {
expect([1, 2, 3]).toContain(1);
expect([1, 2, 3]).toContain(2);
@@ -222,3 +238,69 @@ test("toEvalTo", () => {
expect("*^&%%").not.toEvalTo();
}).toThrow();
});
+
+test("toHaveConfigurableProperty", () => {
+ expect({ foo: 1 }).toHaveConfigurableProperty("foo");
+
+ expect(() => {
+ expect({ foo: 1 }).not.toHaveConfigurableProperty("bar");
+ }).toThrow();
+
+ let o = {};
+ Object.defineProperty(o, "foo", { configurable: true, value: 1 });
+ Object.defineProperty(o, "bar", { configurable: false, value: 1 });
+ expect(o).toHaveConfigurableProperty("foo");
+ expect(o).not.toHaveConfigurableProperty("bar");
+});
+
+test("toHaveEnumerableProperty", () => {
+ expect({ foo: 1 }).toHaveEnumerableProperty("foo");
+
+ expect(() => {
+ expect({ foo: 1 }).not.toHaveEnumerableProperty("bar");
+ }).toThrow();
+
+ let o = {};
+ Object.defineProperty(o, "foo", { enumerable: true, value: 1 });
+ Object.defineProperty(o, "bar", { enumerable: false, value: 1 });
+ expect(o).toHaveEnumerableProperty("foo");
+ expect(o).not.toHaveEnumerableProperty("bar");
+});
+
+test("toHaveWritableProperty", () => {
+ expect({ foo: 1 }).toHaveWritableProperty("foo");
+
+ expect(() => {
+ expect({ foo: 1 }).not.toHaveWritableProperty("bar");
+ }).toThrow();
+
+ let o = {};
+ Object.defineProperty(o, "foo", { writable: true, value: 1 });
+ Object.defineProperty(o, "bar", { writable: false, value: 1 });
+ expect(o).toHaveWritableProperty("foo");
+ expect(o).not.toHaveWritableProperty("bar");
+});
+
+test("toHaveGetterProperty", () => {
+ expect(() => {
+ expect({ foo: 1 }).not.toHaveGetterProperty("bar");
+ }).toThrow();
+
+ let o = {};
+ Object.defineProperty(o, "foo", { get() { return 1; }});
+ Object.defineProperty(o, "bar", { value: 1 });
+ expect(o).toHaveGetterProperty("foo");
+ expect(o).not.toHaveGetterProperty("bar");
+});
+
+test("toHaveSetterProperty", () => {
+ expect(() => {
+ expect({ foo: 1 }).not.toHaveSetterProperty("bar");
+ }).toThrow();
+
+ let o = {};
+ Object.defineProperty(o, "foo", { set(_) { }});
+ Object.defineProperty(o, "bar", { value: 1 });
+ expect(o).toHaveSetterProperty("foo");
+ expect(o).not.toHaveSetterProperty("bar");
+});
diff --git a/Libraries/LibJS/Tests/test-common.js b/Libraries/LibJS/Tests/test-common.js
index a6348327d8..26baf26a3f 100644
--- a/Libraries/LibJS/Tests/test-common.js
+++ b/Libraries/LibJS/Tests/test-common.js
@@ -144,6 +144,18 @@ class Expector {
});
}
+ toBeTrue() {
+ this.__doMatcher(() => {
+ this.__expect(this.target === true);
+ });
+ }
+
+ toBeFalse() {
+ this.__doMatcher(() => {
+ this.__expect(this.target === false);
+ })
+ }
+
toContain(item) {
this.__doMatcher(() => {
// FIXME: Iterator check
@@ -268,6 +280,68 @@ class Expector {
});
}
+ toHaveConfigurableProperty(property) {
+ this.__expect(this.target !== undefined && this.target !== null);
+ let d = Object.getOwnPropertyDescriptor(this.target, property);
+ this.__expect(d !== undefined);
+
+ this.__doMatcher(() => {
+ this.__expect(d.configurable);
+ });
+ }
+
+ toHaveEnumerableProperty(property) {
+ this.__expect(this.target !== undefined && this.target !== null);
+ let d = Object.getOwnPropertyDescriptor(this.target, property);
+ this.__expect(d !== undefined);
+
+ this.__doMatcher(() => {
+ this.__expect(d.enumerable);
+ });
+ }
+
+ toHaveWritableProperty(property) {
+ this.__expect(this.target !== undefined && this.target !== null);
+ let d = Object.getOwnPropertyDescriptor(this.target, property);
+ this.__expect(d !== undefined);
+
+ this.__doMatcher(() => {
+ this.__expect(d.writable);
+ });
+ }
+
+ toHaveValueProperty(property, value) {
+ this.__expect(this.target !== undefined && this.target !== null);
+ let d = Object.getOwnPropertyDescriptor(this.target, property);
+ this.__expect(d !== undefined);
+
+ this.__doMatcher(() => {
+ this.__expect(d.value !== undefined);
+ if (value !== undefined)
+ this.__expect(deepEquals(value, d.value));
+ });
+ }
+
+ toHaveGetterProperty(property) {
+ this.__expect(this.target !== undefined && this.target !== null);
+ let d = Object.getOwnPropertyDescriptor(this.target, property);
+ this.__expect(d !== undefined);
+
+ this.__doMatcher(() => {
+ this.__expect(d.get !== undefined);
+ });
+ }
+
+ toHaveSetterProperty(property) {
+ this.__expect(this.target !== undefined && this.target !== null);
+ let d = Object.getOwnPropertyDescriptor(this.target, property);
+ this.__expect(d !== undefined);
+
+ this.__doMatcher(() => {
+ this.__expect(d.set !== undefined);
+ });
+ }
+
__doMatcher(matcher) {
if (!this.inverted) {
matcher();