-
-
Notifications
You must be signed in to change notification settings - Fork 647
add error-handling exercise #2732
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
base: main
Are you sure you want to change the base?
add error-handling exercise #2732
Conversation
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as outdated.
This comment was marked as outdated.
console.log = jest.fn(); | ||
|
||
try { | ||
processString(''); | ||
} catch { | ||
/* | ||
intentionally left empty, | ||
I expext this call to throw, | ||
but only care about verifying that the finally block is executed | ||
and clean up message logged. | ||
*/ | ||
} | ||
|
||
expect(console.log).toHaveBeenCalledWith('Resource cleaned up'); |
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.
I don't think this will work with the Browser Test Runner, but the idea is not wrong. I can help come up with an easy alternative to fix this.
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.
okay, thank you
…m/A-O-Emmanuel/javascript into implement-error-handling-exercise
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.
I’m not a track maintainer here, just a friendly maintainer from elsewhere on Exercism. I made some more general comments, but whatever SleeplessBytes and Cool-Kat say is the final word. :)
…r-handling.spec.js
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.
What's there is almost done. The only issue I have is that this isn't actually handling any error!
//should throw TypeError if input is not a string | ||
//should throw a general Error if input is an empty string | ||
//should return the uppercase version of the string 'hello' |
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 is part of the instructions so should not be part of our stub
//should throw TypeError if input is not a string | |
//should throw a general Error if input is an empty string | |
//should return the uppercase version of the string 'hello' |
@@ -0,0 +1,6 @@ | |||
export const processString = (input) => { | |||
//TODO: implement this |
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.
In all other stubs we throw new Error('...')
(I don't recall the exact error message). We probably want to use that!
throw new TypeError(); | ||
} | ||
if (input === '') { | ||
throw new 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.
We almost always want a message in an error. We don't need to test the exact message, but throwing an empty error is non-idiomatic.
@@ -0,0 +1,9 @@ | |||
export const processString = (input) => { | |||
if (typeof input !== 'string') { | |||
throw new TypeError(); |
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.
We almost always want a message in an error. We don't need to test the exact message, but throwing an empty error is non-idiomatic.
Implemented the Error Handling practice exercise with solution, tests, and documentation