mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:07:44 +00:00
LibJS: Add more test matchers
This commit is contained in:
parent
5e971c91e3
commit
fc08222f46
8 changed files with 200 additions and 46 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue