ladybird/Userland/Libraries/LibJS/Tests/error-stack.js
Hendiadyoin1 89c82abf1f LibJS: Implement non standard error.stack attribute
All other browser already support this feature.
There is a Stage 1 proposal to standardize this, but it does not seem
to be active.
2022-02-07 14:17:57 +00:00

28 lines
1.1 KiB
JavaScript

test("Anonymous function", function () {
let stackString = (() => {
return Error();
})().stack;
let [header, ...stackFrames] = stackString.split("\n");
expect(header).toBe("Error");
expect(!!stackFrames[0].match(/^ at Error \(.*\/error-stack\.js:3:\d+\)$/)).toBeTrue();
expect(!!stackFrames[1].match(/^ at .*\/error-stack\.js:3:\d+$/)).toBeTrue();
expect(!!stackFrames[2].match(/^ at .*\/error-stack\.js:2:\d+$/)).toBeTrue();
});
test("Named function with message", function () {
function f() {
throw Error("You Shalt Not Pass!");
}
try {
f();
} catch (e) {
let stackString = e.stack;
let [header, ...stack_frames] = stackString.split("\n");
expect(header).toBe("Error: You Shalt Not Pass!");
expect(!!stack_frames[0].match(/^ at Error \(.*\/error-stack\.js:15:\d+\)$/)).toBeTrue();
expect(!!stack_frames[1].match(/^ at f \(.*\/error-stack\.js:15:\d+\)$/)).toBeTrue();
expect(!!stack_frames[2].match(/^ at .*\/error-stack\.js:18:\d+$/)).toBeTrue();
}
});