Check out a free preview of the full Introduction to Node.js, v3 course

The "Additional Test Examples" Lesson is part of the full, Introduction to Node.js, v3 course featured in this preview video. Here's what you'd learn in this lesson:

Scott demonstrates additional examples of tests for different functionalities and use cases.

Preview
Close

Transcript from the "Additional Test Examples" Lesson

[00:00:00]
>> Okay, and then I just had the other tests in here. I don't feel the need to go through and like write all these, but I do wanna just make sure we see some examples, at least I can talk about them. And here we go, sorry. Okay, let's bring those in here.

[00:00:15]
And basically, I just have one for testing to get all notes, which as you can see just mocks a database with some notes. And it just gets all notes and it expects it to be equal, like we don't even test that the notes are in the right shape it's just like is the same thing in the database the same thing that we got back from getAllNotes and that's it.

[00:00:37]
It doesn't care what it is. As long as it is the same thing, and then we have remove note that basically puts some notes in a database, it takes the id 4 to try to remove it, and then it says that result should be undefined, because there is no id 4 in here.

[00:00:58]
So this shouldn't be here, cuz this will return undefined if it couldn't find something to delete, so that should be true. So let's run that and, yeah, they all passed. Cool, and you can write many tests for one thing, like I can write, and you probably will write, multiple tests for just this one removeNote function, right?

[00:01:25]
In fact, you can group these tests together with a, like, describe. So you can say describe. I might just call this the cli app like this like to say just this is describe this thing. And I could put all of this stuff in that describe, so it's kind of like grouped together.

[00:01:48]
And if I run this just like puts it underneath the cli app group right here. So that way you can kinda group your test together cuz on a bigger app at a company, you might have several hundred if not thousands of tests. So looking at them grouped up is a lot easier to deal with.

[00:02:11]
The other thing you might see sometimes depending on the testing framework goes you might not see just tests like this. You might also see some people write it like they'll use it instead of tests or they might say like it. Should do this thing, and then they would write the test.

[00:02:29]
It's the same thing inside of here, but it works just like should, or I'm sorry, it works just like test. It's just a different theoretical approach behind it. Some people like to, it should do this thing or it should not do this thing. Some people just be like I just want to test this thing, test to see if new note does this.

[00:02:48]
So you might see both of those, works the same way though.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now