WEBVTT

00:01.040 --> 00:04.800
So let's start with the testing and I want to start with the unit tests.

00:04.960 --> 00:08.640
So let's say I want to test the router for companies which we created.

00:08.880 --> 00:12.520
So what I will do in the start of the file, I will ask the

00:13.020 --> 00:16.600
copilot to generate tests for me. I still can

00:17.100 --> 00:20.400
specify the libraries as well, but I'm curious about the default result at start.

00:21.040 --> 00:24.880
And by default it uses supertest and

00:25.040 --> 00:28.570
chest. So I will have this setup.

00:28.650 --> 00:31.330
I don't really want to spend time on this one because I don't even want

00:31.830 --> 00:34.970
to use jest. I just want to showcase you how you can replace the whole

00:35.470 --> 00:39.330
file with another unit test framework. And in order to do that I select

00:39.830 --> 00:43.650
all and then I will go for the copilot and then I

00:44.150 --> 00:49.450
will ask to rewrite

00:49.530 --> 00:53.050
this test using Mocha Shine.

00:54.280 --> 00:58.320
So it should suggest me the proper implementation using Mocha

00:58.820 --> 01:02.200
and chime. Cool. Then I can accept it. And you can see that now.

01:02.360 --> 01:06.120
So it's mostly doing the same stuff. But now I'm using

01:06.200 --> 01:09.760
the proper packages I want to use. You still will

01:10.260 --> 01:13.840
see that the sub dependencies you need to be installed.

01:14.340 --> 01:17.080
Let me see if if that resolves our problem,

01:17.960 --> 01:21.540
I'm saving phenomenon and then all of the problems are resolved,

01:22.040 --> 01:25.700
then let's try to run it. In order

01:26.200 --> 01:29.620
to run it you would need to either add or uncomment the test function.

01:30.340 --> 01:33.780
You would also need to rename the test file to spec

01:34.580 --> 01:37.980
because that's how I like to mention it. But you can keep it test and

01:38.480 --> 01:41.940
change the command to test here. And let's see if this runs.

01:44.660 --> 01:48.540
And what do we have attempted to wrap final

01:49.040 --> 01:52.300
D but already wrapped. So let's say I know exactly what is happening,

01:52.800 --> 01:56.420
but let's say I don't and I will just use copilot to

01:56.920 --> 02:01.020
explain it too. So in this case actually CNO library

02:01.520 --> 02:04.860
is trying to stab whatever is already stopped. But we still need

02:05.360 --> 02:08.540
the stop in order for tests to run. So actual problem here is that we

02:09.040 --> 02:11.620
would need to restore the stub every time we run the test,

02:12.110 --> 02:15.350
which is very easy fix. So how we gonna do that? We will go

02:15.850 --> 02:20.190
to the company spec and then we add the after each helper

02:20.430 --> 02:24.390
function which would I

02:24.890 --> 02:28.830
see GitHub even suggest us how to fix that. Now it would be running properly.

02:29.550 --> 02:32.910
All the tests are passing. They all actually correct. And you

02:33.410 --> 02:36.110
the test. If you know how to write this test and you have some previous

02:36.610 --> 02:40.630
experience and after a few implementations of the tests you will have this experience the

02:41.130 --> 02:45.240
test creation. If you don't have any business logic caveats is

02:45.320 --> 02:48.960
quite simple and straightforward. That's a good enough example

02:49.460 --> 02:53.080
to have a real life experience with creating tests for the

02:53.160 --> 02:56.760
GitHub copilot. You can find issues with it later.

02:57.260 --> 03:00.480
If you have a long file or complicated file or some dependencies

03:00.980 --> 03:03.680
are not imported, that could happen. You would need to fix it like I fix

03:04.180 --> 03:07.280
it in this video. But in general it's very helpful to create some kind of

03:07.780 --> 03:08.280
boilerplate test.
