-
Notifications
You must be signed in to change notification settings - Fork 590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deno std_assert lacks a method to validate if a native Error object has the same message attribute as another. #4221
Comments
Looks like jest's internal On the other hand, BTW |
Okay, so I can use // main_test.ts
import {
assertEquals,
assertIsError,
equal,
} from "https://deno.land/std@0.212.0/assert/mod.ts";
import { getError } from "./main.ts";
//...
Deno.test(
'[test2] Should return error object with "missing param: email" message',
() => {
const expectErrObj = new Error("missing param: email");
equal(getError(), expectErrObj);
assertEquals(getError(), expectErrObj);
// const anotherExpectErrObj = new Error('any message');
// equal(getError(), anotherExpectErrObj); // doesn't throw an exception
// assertEquals(getError(), anotherExpectErrObj); // doesn't throw an exception
assertIsError(getError(), Error, "any message"); // throws an exception
},
); Now the exception is triggered by the But I wonder if And if |
Jest does the similar about non enumerable properties, but they have special handling specific to Error objects
Probably we need to document handling of non-enumerable properties..? Another way to solve this confusion might be adding the same special handling for Errors like Jest. |
I find myself in the following scenario: I want to validate if a native Error object returned from any function will have the expected
message
attribute. I noticed that Jest can validate this, but the native Deno testing library cannot. Here's an example with Jest:Prepare the project:
$ mkdir jest-error-assert $ cd jest-error-assert $ npm init -y $ npm i -D jest
Create the
index.js
file in the root:Run Jest with
npx jest
:Okay, notice that [test2] will fail because the Error object returned from the function does not have the expected
message
:missing param: email
. Just modifygetError
to pass the test.Now let's look at an example with Deno's standard assert:
Prepare the project:
$ mkdir deno-error-assert $ cd deno-error-assert $ deno init
Remove everything from
main.ts
andmain_test.ts
, then add:Run the test with
deno test
:See that all tests pass, and there is no equivalent method in the std assert as in Jest to validate this case. Can someone explain why this happens?
My environment:
my os:
The text was updated successfully, but these errors were encountered: