Jest .toThrow(TypeError)
does not match TypeError thrown by new URL
constructor.
Is this a bug or am I doing something wrong?
Jest version is 29.4.2
Test case:
it("throws TypeError when url is invalid", () => {
expect(() => {
new URL(""); // This does not work
// throw new TypeError(); // This works
}).toThrow(TypeError);
})
Output is:
Expected constructor: TypeError
Received constructor: TypeError
Received message: "Invalid URL: "
13 | it("throws TypeError when url is invalid", () => {
14 | expect(() => {
> 15 | new URL("");
| ^
16 | // throw new TypeError();
17 | }).toThrow(TypeError);