-
Notifications
You must be signed in to change notification settings - Fork 620
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
Assertion library custom message should still allow for inclusion of values #878
Comments
We could start allowing callbacks like the following: Deno.test("Test Assert Equal Fail Custom Message", () => {
assertEquals(1, 2, ([num1, num2]) => `Values ${num1} and ${num2} don't match!`);
}); If it fails, then Deno would just call the callback with an array of all of the input (values being asserted together) values passed in. Edit: Actually, I think this belongs in the std repo because that's where all of these asserts were created. |
This would have to do with the std library assertion functions, not the |
@sno2 I think a function is the way to go, but we could pass an object like
|
Will be PR-ing this in the coming days |
Does a template literal address this? Deno.test("Test Assert Equal Fail Custom Message", () => {
const actual = 1;
const expected = 2;
assertEquals(actual, expected, `Values ${actual} and ${expected} don't match!`);
}); |
Yes, perhaps it would be better to accept assertEquals(await foo.getBar(), "foo"); And I don't want to have to store a variable for the result of { // Anonymous block to not re-declare `actual` var
const actual = await foo.getBar();
assertEquals(actual, "foo", `failed to get correct bar, got '${actual}'`);
}
{
const actual = ...
} A callback would not require the anonymous blocks to avoid re-declaring const vars.
|
Moving a concept from #982 : assertEquals(actual, expected, ({ message, actual, expected }) => `...`); seems like the best way to go about this, |
I'm -1 on this. As stated above, using template literals does this fine; from what I gather, the current design works great without it 🙂 WDYT, @kt3k? |
Assertion error messages from I think this issue is now resolved |
This may just be a case of poor documentation, but I've been trying to figure out how I could get "1" and "2" to be included in the msg arg that's output when the test fails. See code example provided in docs below:
It would be nice if it was possible to do something like this:
I've used placeholders $1 and $2 because they're used in VS Code when doing regex replacement, but any other placeholders would be acceptable.
The reason this is useful is that you really want the message to provide the "why" information for the test result expected, but you still want to know what the value of the result actually was and how it differed from the expected value. You could always duplicate the expected value in the message, but then there's two places to change it if you need to change it at some point in future. However, it is essential to be able to output the actual value in the message because there's no way ahead of time that you'll know what that is.
The text was updated successfully, but these errors were encountered: