Skip to content

Commit 3b698a2

Browse files
Fixed tests that were failing in Firefox due to class names in stack traces
1 parent 2dd6e46 commit 3b698a2

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

test/specs/ono-extend.spec.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ describe("Ono.extend()", () => {
5858
expect(error).to.be.an.instanceOf(ValidationError);
5959
expect(error.name).to.equal("ValidationError");
6060
expect(error.message).to.equal("Error #42: Invalid emailAddress");
61-
expect(error.stack).to.satisfy(compareStacks(["createValidationError"]));
61+
expect(error.stack).to.satisfy(compareStacks(
62+
host.error.stack.includesClassNames
63+
? ["ValidationError", "createValidationError"]
64+
: ["createValidationError"]
65+
));
6266
expect(error).to.satisfy(compareKeys("name", "message", "stack", "toJSON", "errorNumber", "fieldName"));
6367

6468
expect(error.toJSON()).to.satisfy(comparePOJO({
@@ -106,7 +110,9 @@ describe("Ono.extend()", () => {
106110
expect(error.name).to.equal("ServerError");
107111
expect(error.message).to.equal("HTTP 500: A server error occurred");
108112
expect(error.stack).to.satisfy(compareStacks(
109-
["createServerError"],
113+
host.error.stack.includesClassNames
114+
? ["ServerError", "createServerError"]
115+
: ["createServerError"],
110116
["createOriginalError"],
111117
));
112118
expect(error).to.satisfy(compareKeys("name", "message", "stack", "toJSON", "method", "url"));

test/utils/host.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,20 @@ module.exports = Object.assign({}, host, {
5858
* Safari normally includes the function name, but not with code coverage instrumentation.
5959
*/
6060
includesFunctionNames: sampleError.stack.includes("getSampleError") && !host.browser.safari,
61+
62+
/**
63+
* Indicates whether the stack traces include error class names
64+
*
65+
* As of April 2020, only Firefox does this
66+
*/
67+
includesClassNames: sampleError.stack.includes("CustomError"),
6168
}
6269
},
6370
});
6471

6572
function getSampleError () {
66-
return new Error("THIS IS THE MESSAGE");
73+
class CustomError extends Error {}
74+
return new CustomError("THIS IS THE MESSAGE");
6775
}
6876

6977
function hasKey (error, key) {

0 commit comments

Comments
 (0)