Current section: Unit Testing 6 exercises

Unit Testing a Function for Error Messages

Loading exercise


00:00 Here's the function that we want to test, getErrorMessage. It takes an unknown argument. If that's a string, it returns an error. If it's an object and it has a message and the message is a string, then it returns that message. Otherwise, it's going to log to the console. That's going to be a bit of a challenge for us later. And it will return unknown error.

00:18 So your task is to write a test for this. It's a perfect use case for a unit test because it's got a little bit of logic in there. And it is a pure function. Well, it's sort of pure, actually. It's a little impure right here. But for the most part, it's mostly pure. So the basic tests are going to be a little easy.

00:36 It takes an argument, returns a value, that sort of thing. So you're going to have a good time with this one. We'll see you when you're done.