1 00:00:00,090 --> 00:00:04,500 In this lecture, we are going to add a custom error message for our tests. 2 00:00:04,500 --> 00:00:09,900 From my experience, Jasmine outputs uninformative unhelpful error messages. 3 00:00:09,900 --> 00:00:12,780 Let's look at an example in your editor. 4 00:00:12,810 --> 00:00:16,890 Open the test file for the tabs container components. 5 00:00:19,030 --> 00:00:24,370 Previously we created to test assertions from within a single test file. 6 00:00:24,370 --> 00:00:26,860 Let's say that both tests fail. 7 00:00:26,950 --> 00:00:32,110 For example, I'm going to change the value in the to b functions to three. 8 00:00:34,210 --> 00:00:36,960 This update should cause the tests to fail. 9 00:00:36,970 --> 00:00:42,940 Let's check out the browser according to the description for the error messages, Jazmin expected two 10 00:00:42,940 --> 00:00:44,040 but got three. 11 00:00:44,050 --> 00:00:45,720 That's not very helpful. 12 00:00:45,730 --> 00:00:49,570 The description doesn't help us debug the problem with our application. 13 00:00:49,570 --> 00:00:53,930 Luckily we can add custom error messages to each test assertion. 14 00:00:53,950 --> 00:00:55,630 Head back to the editor. 15 00:00:55,630 --> 00:01:00,340 Adding error messages can be helpful if you have multiple test assertions. 16 00:01:00,340 --> 00:01:03,250 What if one assertion passed but the other failed? 17 00:01:03,280 --> 00:01:05,810 How would we know which assertion passed? 18 00:01:05,830 --> 00:01:09,700 Our messages should give a clear, concise picture of the problem. 19 00:01:09,730 --> 00:01:16,480 For the first assertion, let's chain a function called with context after the expected function. 20 00:01:18,720 --> 00:01:24,660 The with context function must always be applied after calling the expect function, but before the 21 00:01:24,660 --> 00:01:29,580 matcher, this function allows us to write a custom error message for the assertion. 22 00:01:29,580 --> 00:01:33,390 Let's write the following message tabs did not render. 23 00:01:35,570 --> 00:01:40,640 If this test failed, our query failed to select the elements in the template. 24 00:01:40,670 --> 00:01:43,070 Our message should reflect that results. 25 00:01:43,100 --> 00:01:49,200 Next, let's chain another with context function to the second test assertion. 26 00:01:49,220 --> 00:01:51,320 This time the function will output. 27 00:01:51,320 --> 00:01:55,280 The following error message could not grab component property. 28 00:01:57,360 --> 00:01:59,280 Let's check out the browser. 29 00:02:01,560 --> 00:02:04,230 Our error messages appear on the page. 30 00:02:04,260 --> 00:02:07,960 These messages are more helpful than the default messages. 31 00:02:07,980 --> 00:02:12,150 Whenever possible, I always recommend writing custom messages. 32 00:02:12,150 --> 00:02:18,270 If you're creating multiple assertions, it can help you understand the problem with your test or application. 33 00:02:18,270 --> 00:02:23,340 Before ending this lecture, I'm going to revert the values in the to b function. 34 00:02:23,340 --> 00:02:25,810 We don't want our tests to fail anymore. 35 00:02:25,830 --> 00:02:30,090 Once you've updated your tests, I'll see you in the next lecture.