From the course: JavaScript: Test-Driven Development (ES6)

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Testing asynchronous functions

Testing asynchronous functions - JavaScript Tutorial

From the course: JavaScript: Test-Driven Development (ES6)

Start my 1-month free trial

Testing asynchronous functions

- [Instructor] So now that we've written our first test, we can actually run it. And the way we do that is by opening up a console. You may have noticed that I usually use VS Code's built-in console, but you can use whatever you're comfortable with. And in the root directory of our project, we're going to run npx mocha, and then in quotation marks, "src/**/*.test.js", closing quotation mark, and then --recursive and finally since we're writing our code in ES6 syntax, we have to add --require @babel/register. And if we hit ENTER now, we see that our tests run and the result that we get printed to the console here shows that we only have one test and that our test failed. And this is actually a good thing. Remember that I said in a previous video that in order to do TDD the right way, we need to have a failing test first. This ensures that our test won't give us a false positive. If we run our tests right now and the test we…

Contents