In this lecture, we are going to add a custom error message for our tests.
From my experience, Jasmine outputs uninformative unhelpful error messages.
Let's look at an example in your editor.
Open the test file for the tabs container components.
Previously we created to test assertions from within a single test file.
Let's say that both tests fail.
For example, I'm going to change the value in the to b functions to three.
This update should cause the tests to fail.
Let's check out the browser according to the description for the error messages, Jazmin expected two
but got three.
That's not very helpful.
The description doesn't help us debug the problem with our application.
Luckily we can add custom error messages to each test assertion.
Head back to the editor.
Adding error messages can be helpful if you have multiple test assertions.
What if one assertion passed but the other failed?
How would we know which assertion passed?
Our messages should give a clear, concise picture of the problem.
For the first assertion, let's chain a function called with context after the expected function.
The with context function must always be applied after calling the expect function, but before the
matcher, this function allows us to write a custom error message for the assertion.
Let's write the following message tabs did not render.
If this test failed, our query failed to select the elements in the template.
Our message should reflect that results.
Next, let's chain another with context function to the second test assertion.
This time the function will output.
The following error message could not grab component property.
Let's check out the browser.
Our error messages appear on the page.
These messages are more helpful than the default messages.
Whenever possible, I always recommend writing custom messages.
If you're creating multiple assertions, it can help you understand the problem with your test or application.
Before ending this lecture, I'm going to revert the values in the to b function.
We don't want our tests to fail anymore.
Once you've updated your tests, I'll see you in the next lecture.