1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:27:35 +00:00

LibJS/Tests: Improve expectation error details

This commit is contained in:
Linus Groh 2021-04-23 20:12:10 +02:00
parent 0d2602c900
commit d400be05ec

View file

@ -65,8 +65,7 @@ class ExpectationError extends Error {
this.__doMatcher(() => {
this.__expect(
Object.is(this.target, value),
() =>
"toBe: expected _" + String(value) + "_, got _" + String(this.target) + "_"
() => `toBe: expected _${String(value)}_, got _${String(this.target)}_`
);
});
}
@ -75,11 +74,11 @@ class ExpectationError extends Error {
toBeCloseTo(value) {
this.__expect(
typeof this.target === "number",
() => "toBeCloseTo: target not of type number"
() => `toBeCloseTo: expected target of type number, got ${typeof value}`
);
this.__expect(
typeof value === "number",
() => "toBeCloseTo: argument not of type number"
() => `toBeCloseTo: expected argument of type number, got ${typeof value}`
);
this.__doMatcher(() => {
@ -133,7 +132,10 @@ class ExpectationError extends Error {
toBeDefined() {
this.__doMatcher(() => {
this.__expect(this.target !== undefined, () => "toBeDefined: target was undefined");
this.__expect(
this.target !== undefined,
() => "toBeDefined: expected target to be defined, got undefined"
);
});
}
@ -153,7 +155,10 @@ class ExpectationError extends Error {
this.__doMatcher(() => {
this.__expect(
this.target === undefined,
() => "toBeUndefined: target was not undefined"
() =>
`toBeUndefined: expected target to be undefined, got _${String(
this.target
)}_`
);
});
}
@ -162,7 +167,7 @@ class ExpectationError extends Error {
this.__doMatcher(() => {
this.__expect(
isNaN(this.target),
() => "toBeNaN: target was _" + String(this.target) + "_, not NaN"
() => `toBeNaN: expected target to be NaN, got _${String(this.target)}_`
);
});
}