WEBVTT

00:01.220 --> 00:09.650
Now, let's create a new file inside of test and let's call it let's call it parser the test that James.

00:11.120 --> 00:19.460
And then let's write out a contest parser and then let's say require.

00:21.440 --> 00:29.150
And then we go up one directory into the root directory where we have where we create a new file, we

00:29.150 --> 00:32.030
call it parser that is.

00:33.960 --> 00:42.090
And then it's important file here, so we have parser with two dots because we go one directory up and.

00:43.810 --> 00:46.270
So in here, we can ride the test itself.

00:46.720 --> 00:54.430
Usually you can ride the test out like something with the IT word and then you can ride it should.

00:55.810 --> 01:05.890
Give for so then you can call a method in here and test it out so we can do a function, call here and

01:05.890 --> 01:19.000
call, for example, and we can say consed result equals Peiser that at and then we can pass into some

01:19.000 --> 01:21.720
variables, for example, two and two.

01:22.630 --> 01:28.270
And then we say we expect the result to be.

01:30.440 --> 01:37.370
Four million, so that's our first test that we just written here, where we test the atmosphere inside

01:37.370 --> 01:38.120
of parser.

01:38.720 --> 01:41.980
Now notice that we've written out the test first here.

01:42.260 --> 01:44.250
We haven't written out the code yet.

01:44.570 --> 01:49.190
That's what you mean when you say test driven development or TDD.

01:50.160 --> 01:56.490
And it's really nice to do this with scraping, because it means we're not going to hit the website

01:56.490 --> 02:03.990
as we're developing our scraper anyway onto this little example we have here for adding let's try and

02:03.990 --> 02:08.580
run our test now and we should see a test that is fading now.

02:08.760 --> 02:12.990
So we see yarn run test.

02:13.780 --> 02:19.050
Remember, test is what we have inside of the package to chasten with the scripts.

02:19.050 --> 02:26.270
And then we have test in here so you can run test is essentially going to run just that virtual.

02:27.420 --> 02:28.500
Let's see how it works.

02:28.740 --> 02:30.330
So we'll see you on one test.

02:30.750 --> 02:38.640
And now it's this one test suit or one test has failed and it says pass the dart at.

02:38.640 --> 02:44.370
It's not a function, which is true because there's no functions at all instead of possible.

02:46.170 --> 02:54.600
So that's the reason why we also write out the test before we write the code, is to basically make

02:54.600 --> 02:58.850
sure that the code is more testable before you write the code.

02:59.280 --> 03:07.290
And secondly, we also ensure that the test is actually working instead of us riding out the test and

03:07.290 --> 03:12.210
the test goes green, even though the test is not actually working.

03:13.260 --> 03:19.380
So that's why you want to see a failing test first and then you want to write out the code to make the

03:19.380 --> 03:25.890
test pass, because then you know that the test is working because it started out by failing.

03:27.150 --> 03:32.910
If it just starts out by going green right now, even though I haven't written the test or written the

03:32.910 --> 03:37.470
code yet, I would know something is wrong with this test.
