mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-29 19:10:26 +00:00
LibJS: Improve Error/NativeError tests
Some of this stuff is already tested properly in the name and message prototype tests, so let's focus on covering all error types here as well instead.
This commit is contained in:
parent
8b84a0ff69
commit
8d77a3297a
Notes:
sideshowbarker
2024-07-18 12:24:16 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/8d77a3297a0 Pull-request: https://github.com/SerenityOS/serenity/pull/8007
1 changed files with 31 additions and 15 deletions
|
@ -1,18 +1,34 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Error).toHaveLength(1);
|
||||
expect(Error.name).toBe("Error");
|
||||
});
|
||||
describe("normal behavior", () => {
|
||||
test("length is 1", () => {
|
||||
expect(Error).toHaveLength(1);
|
||||
expect(EvalError).toHaveLength(1);
|
||||
expect(RangeError).toHaveLength(1);
|
||||
expect(ReferenceError).toHaveLength(1);
|
||||
expect(SyntaxError).toHaveLength(1);
|
||||
expect(TypeError).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("name", () => {
|
||||
[Error(), Error(undefined), Error("test"), Error(42), Error(null)].forEach(error => {
|
||||
expect(error.name).toBe("Error");
|
||||
test("name matches constructor name", () => {
|
||||
expect(Error.name).toBe("Error");
|
||||
expect(EvalError.name).toBe("EvalError");
|
||||
expect(RangeError.name).toBe("RangeError");
|
||||
expect(ReferenceError.name).toBe("ReferenceError");
|
||||
expect(SyntaxError.name).toBe("SyntaxError");
|
||||
expect(TypeError.name).toBe("TypeError");
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
expect(Error()).toBeInstanceOf(Error);
|
||||
expect(new Error()).toBeInstanceOf(Error);
|
||||
expect(EvalError()).toBeInstanceOf(EvalError);
|
||||
expect(new EvalError()).toBeInstanceOf(EvalError);
|
||||
expect(RangeError()).toBeInstanceOf(RangeError);
|
||||
expect(new RangeError()).toBeInstanceOf(RangeError);
|
||||
expect(ReferenceError()).toBeInstanceOf(ReferenceError);
|
||||
expect(new ReferenceError()).toBeInstanceOf(ReferenceError);
|
||||
expect(SyntaxError()).toBeInstanceOf(SyntaxError);
|
||||
expect(new SyntaxError()).toBeInstanceOf(SyntaxError);
|
||||
expect(TypeError()).toBeInstanceOf(TypeError);
|
||||
expect(new TypeError()).toBeInstanceOf(TypeError);
|
||||
});
|
||||
});
|
||||
|
||||
test("message", () => {
|
||||
expect(Error().message).toBe("");
|
||||
expect(Error(undefined).message).toBe("");
|
||||
expect(Error("test").message).toBe("test");
|
||||
expect(Error(42).message).toBe("42");
|
||||
expect(Error(null).message).toBe("null");
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue