Check out a free preview of the full JavaScript Testing Practices and Principles course

The "Your First Test Exercise" Lesson is part of the full, JavaScript Testing Practices and Principles course featured in this preview video. Here's what you'd learn in this lesson:

Kent reviews the first exercise where the audience is instructed to access the GitHub repository that was previously cloned and to write a simple test in pure JavaScript that reveals the bug and throws an error.

Preview
Close

Transcript from the "Your First Test Exercise" Lesson

[00:00:00]
>> Kent C. Dodds: So what is a JavaScript Test? This is actually a link to a blog that I posted a couple weeks ago, back in January, where I basically have a blog post forum of what we're about to do. But, now we're gonna jump into the project, and you're gonna do this.

[00:00:18]
So if you can open up your projects. Open up your terminal and the project and your editor. We're gonna start in this other directory and what's a test? And that you'll start in one.todo.js. And in here there are some comments to explain what you're supposed to do. But the idea with all of these is that you're going to write a framework, and then you'll write an assertion library.

[00:00:51]
But this first one, we're going to write the simplest form of a test that you could possibly imagine.
>> Kent C. Dodds: And so to run this, you're gonna want to change your directory into this where we are right now so you'll cd into other what's a test? And then for each one of these it will say and then run this code with and then command so for us it's node1.todo.

[00:01:22]
And you'll know that you got it right when your when running that actually throws a bug, or it throws an error because there is a bug. Who found the bug? Yeah, Peter found it, what is it?
>> Speaker 2: Sum is actually subtracting and sum-
>> Kent C. Dodds: Yeah. Yeah, so that's intentional because a huge part of testing frameworks job is to, show you now the errors and you get error messages so you can both know what's wrong and also know how to fix it.

[00:01:55]
And so, yeah so sum is intentionally broken in this way. So, what your job is to write additional code, presumably after this code to throw a useful error to validate whether sum is working or not. So you use sum and then you validate that it is returning what it should be, an d if it's not, then you throw an error.

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