-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
doc: add throw example #52417
doc: add throw example #52417
Conversation
Review requested:
|
I'm not sure this belongs in Line 2184 in bf39716
We could add a link to |
the idea is to have one or more examples in |
So @aduh95 you thinks it's better to add link to assert instead of having code snippet ? |
|
||
function failFunction() { | ||
throw new Error('This error will be caught'); | ||
} | ||
|
||
// It's the way to catch expected errors i your test | ||
test('test catch error', (t) => { | ||
assert.throws(() => failFunction(), { | ||
message: 'This error will be caught', | ||
}); | ||
}); |
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.
Let's remove this one that feels out of place. Instead, what we can do is modify synchronous passing test
and asynchronous passing test
to include use of assert.throws()
and await assert.rejects()
.
Also, we advice against using error.message
to prefer error.code
, let's showcase that in our docs.
function failFunction() { | |
throw new Error('This error will be caught'); | |
} | |
// It's the way to catch expected errors i your test | |
test('test catch error', (t) => { | |
assert.throws(() => failFunction(), { | |
message: 'This error will be caught', | |
}); | |
}); |
error() { | ||
throw new Error('error'); | ||
}, |
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.
This code sample is about mocking methods, I don't think assert.throws
has anything to do with it.
error() { | |
throw new Error('error'); | |
}, |
assert.throws(() => number.error(), { | ||
message: 'error', | ||
}); | ||
|
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.
assert.throws(() => number.error(), { | |
message: 'error', | |
}); |
I thinks add ressource on learn section is more appropriate |
Add example of throw
Fix: #52357
make lint-js-doc