WEBVTT

00:00.080 --> 00:02.510
So let's just write out an example here.

00:02.510 --> 00:06.770
I'm just going to write out an example of what data we're actually trying to get.

00:06.770 --> 00:09.710
So we want an array of these listings.

00:11.000 --> 00:16.190
We have an array here containing objects that have properties of the data.

00:16.190 --> 00:21.020
So we have a title, for example, it could have a title of.

00:21.790 --> 00:25.360
All the term time, all the time.

00:25.360 --> 00:28.140
And bluegrass fiddle lessons.

00:28.150 --> 00:29.740
That's the title here.

00:30.660 --> 00:32.010
So we have that.

00:32.160 --> 00:39.270
And then there's a URL, which is the URL you have when you click on the link here.

00:39.930 --> 00:40.860
It's this one.

00:42.750 --> 00:45.420
And then a date.

00:45.450 --> 00:46.650
It was posted.

00:47.820 --> 00:50.580
That could be a JavaScript date object.

00:50.580 --> 00:55.380
So something like 2009, uh, something like this.

00:57.130 --> 00:58.990
And then we have.

00:59.230 --> 01:00.340
What else did we have?

01:00.370 --> 01:01.690
We have the neighborhood.

01:02.470 --> 01:06.910
So if I sample San Francisco, we have their.

01:08.210 --> 01:13.370
So those are the different data points that we want from all the different listings.

01:13.490 --> 01:17.450
And we're basically going to get an array of all these objects.

01:17.900 --> 01:22.820
So now we want to actually kind of wrote the test sort of already.

01:22.820 --> 01:28.760
So we say that, um, it should give the.

01:30.150 --> 01:31.020
Correct.

01:31.630 --> 01:33.100
Listing object.

01:34.520 --> 01:40.550
So we say here, you should return this object here.

01:41.880 --> 01:42.870
From parser.

01:42.870 --> 01:52.980
So we say const results or const listings from parser dot listings and there we pass in some HTML that

01:52.980 --> 02:01.170
we already defined up here in the in the before all, that's where we read the HTML file and define

02:01.170 --> 02:02.010
the variable.

02:02.370 --> 02:11.640
And then we pass in the we pass in the HTML text to parser dot listings where we parse it and get the

02:11.640 --> 02:12.300
data.

02:13.050 --> 02:21.540
So then we expect that well listings is the length of listings should be.

02:22.380 --> 02:28.660
120 because there's 120 listings on this page.

02:29.320 --> 02:32.380
And then we could also say that we expect.

02:33.620 --> 02:34.820
Listings.

02:35.690 --> 02:40.400
The first object of the title to be.

02:42.090 --> 02:44.220
This title you have up here?

02:48.160 --> 02:56.320
And then we can say we expect listings the first object to be or the URL.

02:58.380 --> 02:59.430
To be.

03:01.190 --> 03:03.440
This URL we have up here.

03:05.430 --> 03:06.600
Let's paste that in.

03:08.620 --> 03:10.720
And for good measures.

03:10.720 --> 03:15.790
We actually want to have a test for each thing that you have.

03:16.240 --> 03:23.140
I like to have a test for each thing so that you can very fast see what went wrong or what is missing.

03:23.560 --> 03:29.950
That means we have a test for the title, a test for the URL, and maybe a test for the length as well.

03:30.280 --> 03:33.430
So we could have a test here that says it.

03:34.490 --> 03:37.550
Should get correct title.

03:40.620 --> 03:44.160
And we say const listings.

03:45.080 --> 03:48.950
Parser listings pass into HTML.

03:49.400 --> 03:56.120
And then we say we expect listings zero the first listing to be this title.

03:57.000 --> 03:59.760
And then I can easily see that.

03:59.760 --> 04:07.140
Okay, this test with the title is failing so I can go and look at the code more efficiently this way.

04:09.240 --> 04:10.350
Now, let's see.

04:10.350 --> 04:10.980
Let's see.

04:10.980 --> 04:12.860
We also need one for the URL.

04:15.380 --> 04:18.620
It should get correct URL.

04:21.900 --> 04:24.810
And in here, we just cut that.

04:26.020 --> 04:34.780
And now instead of having this concert listings for every test, then we can simply use our before all

04:34.780 --> 04:35.950
function again.

04:36.340 --> 04:39.610
The one up here to define this listing variable.

04:40.370 --> 04:51.950
So we can say let listings up here and say listings is equal to parser dot listings and we paste or

04:51.950 --> 04:55.900
we pass in the HTML into the function here.

04:55.910 --> 05:03.470
And then we have this array of listings and then we can test this listings array inside each function.

05:03.780 --> 05:07.670
Then we don't have to write out const listings equals.

05:08.830 --> 05:13.520
Uh, this call here for every function type or every test type we have.

05:13.550 --> 05:19.280
So I can delete this one now because we have it defined in the global scope.

05:20.900 --> 05:22.520
Now we have.

05:22.790 --> 05:27.050
We also have to test for the neighborhood.

05:29.170 --> 05:31.600
Should get Hood from listing.

05:41.260 --> 05:49.150
So we say expect listings first one to be or not to be.

05:49.480 --> 05:50.310
What should it be?

05:50.320 --> 05:52.240
It should be San Francisco.

05:55.290 --> 05:57.300
And then we also need to get the date.

05:57.300 --> 06:03.330
So we say it should get correct date from listing.

06:06.660 --> 06:08.880
And then we say we expect.

06:10.140 --> 06:11.490
Listings.

06:11.970 --> 06:13.080
Zero.

06:13.860 --> 06:15.690
Date Posted.

06:16.590 --> 06:17.700
To be.

06:18.600 --> 06:26.970
And here we have to look at the Chrome developer tools and find out exactly what the date time is.

06:26.970 --> 06:33.780
So I'm going to go into Chrome Developer Tools and I select an element and I click on the little date

06:33.780 --> 06:34.740
we have here.

06:35.740 --> 06:42.430
And I can see the exact date here inside the datetime attribute, and we just copy that.

06:44.450 --> 06:51.470
So then I say I want it to be equal to a new JavaScript date of this date.

06:53.120 --> 06:54.770
And then.

06:55.870 --> 06:57.820
I think that should be it.

06:59.160 --> 07:00.210
Um, okay.

07:00.210 --> 07:03.600
So I'm going to delete this example.

07:03.600 --> 07:09.600
That's just for showing you guys what kind of data we are trying to get or how it's going to look.

07:09.630 --> 07:11.730
So I'm going to delete that now.

07:14.110 --> 07:17.410
So now we have all of our test out here.

07:17.410 --> 07:20.170
We have a one for the length.

07:20.170 --> 07:22.060
It should give the correct.

07:22.860 --> 07:29.790
Number of listings to be 120 should get the hood from the listing.

07:29.790 --> 07:31.230
San Francisco.

07:31.470 --> 07:35.370
It should get the correct date, which is the date posted.

07:36.290 --> 07:38.960
And it should get the correct URL.

07:39.990 --> 07:42.060
And it should get the correct title.

07:43.100 --> 07:49.610
So those four things are what we are looking for in the data of each of the listings.

07:52.230 --> 07:57.030
Now we should check out our test and we see we have.

07:57.760 --> 07:59.680
Actually six failed tests.

08:01.110 --> 08:07.530
Because the before all function is failing, because listings is not a function inside parser.

08:09.220 --> 08:12.460
And actually, I think we should just remove this.

08:12.490 --> 08:14.440
It should give four functions.

08:14.440 --> 08:15.970
Let's go and remove that.

08:19.330 --> 08:24.130
Because we are not going to be adding any numbers anymore inside this.
