Throwing an Error and Testing It
Understand how to proactively manage invalid inputs by throwing errors like TypeError or RangeError in your functions. Learn the correct way to test error throwing in Jest, including passing functions to expect and validating error messages with strings or regular expressions.
We'll cover the following...
We'll cover the following...
Good programming practice must pro-actively consider bad function inputs and handle them within the function.
Throwing an error
We’ve thought briefly about strings, negative numbers, and fractions as inputs into getCollatzSequence. What about array inputs or objects? The easiest solution is to throw an error if the input is not a positive whole number. ...