1 00:00:00,060 --> 00:00:05,390 In this lecture, we are going to prepare our app for testing before getting started. 2 00:00:05,400 --> 00:00:11,760 You should launch the test runner with the NPM run test command for the rest of this section. 3 00:00:11,760 --> 00:00:14,220 You should always have this command running. 4 00:00:14,220 --> 00:00:18,270 We are going to be writing a few tests with Karma and Jasmine. 5 00:00:18,270 --> 00:00:22,470 Once the server is running, let's inspect the console for errors. 6 00:00:22,470 --> 00:00:25,140 Dozens of errors will appear in the console. 7 00:00:25,170 --> 00:00:26,880 The question is why? 8 00:00:26,910 --> 00:00:28,430 The reason is simple. 9 00:00:28,440 --> 00:00:35,040 During the development of our application, test, files were generated for each component service pipe 10 00:00:35,040 --> 00:00:36,180 and class. 11 00:00:36,210 --> 00:00:41,910 A test file can be identified by its extension, which is spec tests. 12 00:00:41,940 --> 00:00:45,420 Throughout most of this course, we've ignored these files. 13 00:00:45,450 --> 00:00:50,100 The test command will scan our project files with these extensions. 14 00:00:50,100 --> 00:00:55,620 If a file has this extension, the test will be loaded with our application in the browser. 15 00:00:55,620 --> 00:01:00,270 Angular recommends defining test files with their relative classes. 16 00:01:00,270 --> 00:01:06,180 For example, if you're writing a test for the app component, the test for this component should be 17 00:01:06,180 --> 00:01:12,450 placed in the same directory as the component scattered through our project are test files. 18 00:01:12,450 --> 00:01:15,930 Initially, Angular will prepare your test files. 19 00:01:15,930 --> 00:01:22,560 For example, let's look at the app dot component dot spec dot test file. 20 00:01:24,900 --> 00:01:27,960 Dozens of lines of code are written inside this file. 21 00:01:27,990 --> 00:01:31,590 Angular will create initial tests for your classes. 22 00:01:31,620 --> 00:01:33,310 Here in lies the problem. 23 00:01:33,330 --> 00:01:37,540 The tests are designed to pass for the original copy of the component. 24 00:01:37,560 --> 00:01:42,560 Since the beginning we've performed dozens of changes to the app component. 25 00:01:42,570 --> 00:01:45,030 Therefore, the tests will fail. 26 00:01:45,060 --> 00:01:47,550 This goes for the other tests as well. 27 00:01:47,580 --> 00:01:50,250 All tests are broken for this section. 28 00:01:50,250 --> 00:01:53,940 We are going to start with a clean slate on the sidebar. 29 00:01:53,970 --> 00:01:56,550 Open the project with the file Explorer. 30 00:01:58,720 --> 00:02:00,160 Inside the search field. 31 00:02:00,160 --> 00:02:03,910 Search for files with the suspects extension. 32 00:02:06,220 --> 00:02:10,280 The Explorer will present us with a complete list of our test files. 33 00:02:10,300 --> 00:02:12,990 You have two options at your disposal. 34 00:02:13,000 --> 00:02:15,220 You can delete all test files. 35 00:02:15,250 --> 00:02:18,650 Alternatively, you can rename the test files. 36 00:02:18,670 --> 00:02:21,420 I prefer to rename the test files. 37 00:02:21,430 --> 00:02:25,110 We'll be able to revisit the test files in future lectures. 38 00:02:25,120 --> 00:02:33,130 Let's rename the files by changing the extension from spec to spec broken tests. 39 00:02:33,130 --> 00:02:36,730 I'm going to perform this renaming for each test file. 40 00:02:42,060 --> 00:02:42,770 Great. 41 00:02:42,780 --> 00:02:45,580 The test runner will ignore every test file. 42 00:02:45,600 --> 00:02:47,910 We are starting with a fresh slate. 43 00:02:47,940 --> 00:02:52,250 It'll be easy to identify which tests are broken by their file name. 44 00:02:52,260 --> 00:02:56,310 In the next lecture, let's begin writing our first test.