Check out a free preview of the full Introduction to JavaScript course:
The "Introduction to Testing" Lesson is part of the full, Introduction to JavaScript course featured in this preview video. Here's what you'd learn in this lesson's course:

Brian explains what development tests are and why they are important when writing JavaScript code.

Get Unlimited Access Now

Transcript from the "Introduction to Testing" Lesson

[00:00:03]
>> Brian Holt: So let's talk about what your assignment is for today and,
>> Brian Holt: We will let you get on with your day. The one that you're actually gonna do here is make the test pass. So make sure you're here on make the tests pass.
>> Brian Holt: We'll be doing the DOM tomorrow, okay.

[00:00:31]
Make the test pass.
>> Brian Holt: So in software programming, there is a concept called testing. And what testing is, is it's writing code to make sure that your other code works. Now that kind of seems counterintuitive, why would I wanna write more code? But in general, a good amount of testing will help you have confidence whenever you release code into the wild, right?

[00:00:57]
So if I have some sort of module that takes an object, person object, and returns an address. I could write a couple of test cases like make sure that this object works this particular way, right, like it returns a valid address. The reason why that's helpful is over time, bits of code get changed, things get deleted, things get moved around and you can accidentally break other parts of your code.

[00:01:23]
So if I change something over here, I accidentally broke something over here in my application, right? Tests help you mitigate that sort of problem, right? You write code that validates, this will still work. And then you run that tests every single time before you launch your code into production.

[00:01:37]
Does that make sense? So here, what I have done for you is I've wrote a bunch of tests for you. And I want you to make these tests pass, okay? You don't have to write any HTML or CSS today. And then I'm going to show you just a couple of little tips and tricks with this.

[00:01:58]
We're going to be using something called Jasmine, which is a testing framework for JavaScript. Not that you really need to know anything about it, you don't need to know about Jasmine. But in general, tests are going to look like that. So I'm going to say expect the answer of (addTwo(5)).toEqual(7), right?

[00:02:19]
And now, if I ever mess up what add to does in the future, that test will fail and it won't let me release my code, right? It won't let me publish that to the Internet, so that's the point of tests. And, yeah, again, I wrote this for you.

[00:02:35]
And now you need to go write the code that makes the test pass. I do have a link down here. I did give you a question where I asked you to write sort. You can write sort like I just showed you. But if you actually want to write it by hand as well, you are welcome to.

[00:02:48]
It is difficult, but you can do it.