1 00:00:06,510 --> 00:00:09,060 - We're going to use Jest as the test framework 2 00:00:09,060 --> 00:00:11,430 for most of the tests in this video series. 3 00:00:11,430 --> 00:00:13,350 So obviously the first thing we need to do 4 00:00:13,350 --> 00:00:15,832 is to install Jest onto our machines. 5 00:00:15,832 --> 00:00:17,400 There were two ways to do that. 6 00:00:17,400 --> 00:00:20,580 You can either use Node Package Manager, NPM 7 00:00:20,580 --> 00:00:22,170 or you can use Yarn. 8 00:00:22,170 --> 00:00:23,490 Let's take a look at both techniques. 9 00:00:23,490 --> 00:00:25,110 Both are fine. 10 00:00:25,110 --> 00:00:28,200 Personally I tend to use Node Package Manager 11 00:00:28,200 --> 00:00:30,600 but Yarn is equally good. 12 00:00:30,600 --> 00:00:33,090 So if you want to use Node Package Manager 13 00:00:33,090 --> 00:00:34,470 to install Jest, 14 00:00:34,470 --> 00:00:35,640 obviously the first thing 15 00:00:35,640 --> 00:00:38,820 you have to have Node Package Manager installed. 16 00:00:38,820 --> 00:00:41,520 NPM comes with nodejs. 17 00:00:41,520 --> 00:00:44,070 So if you go to node.js.org 18 00:00:44,070 --> 00:00:46,590 and download Node.js from there. 19 00:00:46,590 --> 00:00:49,770 Just click the long term support button. 20 00:00:49,770 --> 00:00:52,710 It takes a while to download Node.js. 21 00:00:52,710 --> 00:00:54,750 It installs Python as well, 22 00:00:54,750 --> 00:00:56,550 plus some C++ libraries. 23 00:00:56,550 --> 00:00:59,610 So you have to give it a good five minutes to install it. 24 00:00:59,610 --> 00:01:01,920 Once you've done that, you can then use NPM 25 00:01:01,920 --> 00:01:05,040 to install any libraries you need, like Jest. 26 00:01:05,040 --> 00:01:07,050 So let's do that now. 27 00:01:07,050 --> 00:01:08,310 Just run this command, 28 00:01:08,310 --> 00:01:11,610 npminstall, the --global flag 29 00:01:11,610 --> 00:01:14,613 will install Jest globally 30 00:01:14,613 --> 00:01:17,370 in the NPM folder on your machine. 31 00:01:17,370 --> 00:01:18,570 So you can run Jest 32 00:01:18,570 --> 00:01:21,720 from any directory you want to thereafter. 33 00:01:21,720 --> 00:01:24,450 Okay. So open up a terminal window or command window. 34 00:01:24,450 --> 00:01:27,390 Run that command and you now have Jest 35 00:01:27,390 --> 00:01:29,490 installed on your machine. 36 00:01:29,490 --> 00:01:33,750 If you prefer to use Yarn then... 37 00:01:33,750 --> 00:01:35,250 Well, first of all 38 00:01:35,250 --> 00:01:38,070 if you haven't got Yarn installed on your machine 39 00:01:38,070 --> 00:01:41,430 you can actually use NPM to install Yarn 40 00:01:41,430 --> 00:01:43,950 which seems a little bit roundabout. 41 00:01:43,950 --> 00:01:45,030 So you can say this, 42 00:01:45,030 --> 00:01:48,210 open up a terminal window, or command window, 43 00:01:48,210 --> 00:01:52,440 npm install --global, install the Yarn library, 44 00:01:52,440 --> 00:01:53,613 or the Yarn tool. 45 00:01:54,480 --> 00:01:55,890 Once you've installed Yarn, 46 00:01:55,890 --> 00:01:57,360 and that takes a moment or two, 47 00:01:57,360 --> 00:02:01,110 you can then use Yarn to install Jest, like this. 48 00:02:01,110 --> 00:02:02,490 So in the command window 49 00:02:02,490 --> 00:02:04,470 or in your terminal window, 50 00:02:04,470 --> 00:02:06,630 yarn global add. 51 00:02:06,630 --> 00:02:09,270 So in the global Yarn folder, 52 00:02:09,270 --> 00:02:11,610 we are adding the Jest library. 53 00:02:11,610 --> 00:02:12,870 Okay. So in both cases 54 00:02:12,870 --> 00:02:15,840 we should now have Jest installed on our machine 55 00:02:15,840 --> 00:02:17,670 ready to use. 56 00:02:17,670 --> 00:02:20,733 To verify that Jest is installed properly, 57 00:02:21,810 --> 00:02:24,300 just run this command from a terminal, 58 00:02:24,300 --> 00:02:28,260 jest --version and all being well, 59 00:02:28,260 --> 00:02:30,390 it should show a version number. 60 00:02:30,390 --> 00:02:32,460 So when I'm running this demo myself 61 00:02:32,460 --> 00:02:35,430 the latest version is 27.5.1. 62 00:02:35,430 --> 00:02:38,100 Obviously, by the time you get to watch this video 63 00:02:38,100 --> 00:02:39,360 it might be a different number. 64 00:02:39,360 --> 00:02:41,760 Probably will be but that should be fine. 65 00:02:41,760 --> 00:02:43,143 Let's do that. 66 00:02:43,143 --> 00:02:46,143 (keyboard clicking) 67 00:02:47,820 --> 00:02:50,580 Okay. So I have Jest installed on my machine. 68 00:02:50,580 --> 00:02:52,140 It was quite straightforward. 69 00:02:52,140 --> 00:02:54,270 What we're going to see in the next section 70 00:02:54,270 --> 00:02:56,580 is how to write some simple tests 71 00:02:56,580 --> 00:03:00,423 and to run them using the Jest execution framework.