Running the First Test — Transcript

Transcript of the free Vue.js lesson Running the First Testwatch the video lesson.

In order to run our first test, we need some code. Here we have a simple user class. We want to see if an initiated user would return the correct full name when the name property gets called. Let's start to write our test just below the given code.

That is needed to define a new test. At this point, it should be noted that it and test are synonyms and can be used as preferred. There's one other function we should look at right away before we start writing the test. I recommend grouping tests, and this is possible using the describe function.

This helps us staying organized and will create a nice output in the terminal. But now let's write the test. Let's start with the new user object. All right, so after initiating the user, we actually want to check if the user matches our expected outcome.

In Jest, These are called expectations as well. Let me write it down and it will look very intuitive. That's it. Let's now try to run this test.

Let's see what happens if we execute Jest. Not what we hoped for. This is simply due to the fact that Jest needs to know about files where tests are located. js.

spec. and mostly refer to tests as specs as well. Spec comes from specifications, and many engineers refer to tests by the name specs. So let's rename our file and rerun Jest.

We now see a passing test, and the console gives us a well-structured output. There's one thing left we should try to take care of right away. We do not want our specs to live alongside the actual code in the same file. We're going to pull out the user class, and put it in an extra file that we can import.

So this is way cleaner and more reflective of the reality. To end this video, let's run the test once again and see it now also works with imports as expected. In order to run our first test, we need some code. Here we have a simple user class.

We want to see if an initiated user would return the correct full name when the name property gets called. Let's start to write our test just below the given code. That is needed to define a new test. At this point, it should be noted that it and test are synonyms and can be used as preferred.

There's one other function we should look at right away before we start writing the test. I recommend grouping tests, and this is possible using the describe function. This helps us staying organized and will create a nice output in the terminal. But now let's write the test.

Let's start with the new user object. All right, so after initiating the user, we actually want to check if the user matches our expected outcome. In Jest, These are called expectations as well. Let me write it down and it will look very intuitive.

That's it. Let's now try to run this test. Let's see what happens if we execute Jest. Not what we hoped for.

This is simply due to the fact that Jest needs to know about files where tests are located. js. spec. and mostly refer to tests as specs as well.

Spec comes from specifications, and many engineers refer to tests by the name specs. So let's rename our file and rerun Jest. We now see a passing test, and the console gives us a well-structured output. There's one thing left we should try to take care of right away.

We do not want our specs to live alongside the actual code in the same file. We're going to pull out the user class, and put it in an extra file that we can import. So this is way cleaner and more reflective of the reality. To end this video, let's run the test once again and see it now also works with imports as expected.