-
Notifications
You must be signed in to change notification settings - Fork 1.4k
show error message if literal is thrown - fixes #661 #683
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
Conversation
By analyzing the blame information on this pull request, we identified @kasperlewau, @ariporad and @sotojuan to be potential reviewers |
Can you also add what was thrown to the message, the type and value. Might be helpful. |
Also added the types to |
Not really necessary as they're only useful in an AssertionError. |
But it's ok to keep it like this? |
try { | ||
fn(); | ||
} catch (error) { | ||
if (error && typeof error !== 'object') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this check is good enough in every case though. Should I use something like is-error instead? Because now someone can still throw {foo: 'bar'}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for is-error.
Hi @SamVerschueren. I don't think this PR is the correct solution to #661. First some background.
These lines implement that error message comparison validation. In this example the error message does not compare ( import test from 'ava'
async function fn() {
return Promise.reject('foo');
}
test(async t => {
t.throws(fn(), 'foo');
}); The reason you get In other words we need to check the error coming out of |
Hi @novemberborn. Thanks for looking into this. Can you explain why it's not a solution for #661? I read your post multiple times but can't really find an answer :). After looking into it again, I might have found a solution that's "cleaner" and might fit your approach more. I will make another PR with the new solution so we can compare and make sure I understand you correctly.
Yes I know, I had it wrong in the original issue. I'm not touching those lines. I thought that was the issue but after diving deeper I noticed it's a custom compare function for |
|
I disagree. #468 (comment) |
I agree with @jamestalmage although you might argue if AVA should enforce this best practice... |
I think it protects you from careless mistakes. |
@SamVerschueren hope it's OK if I close this for now. I reckon resolving #661 will require some more changes. |
This PR fixes #661 which prints
Expected an object to be thrown.
. It's the same error message that ESLint shows when trying to throw a literal. Feel free to provide feedback of any kind.