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 - JavaScript Tutorial
From the course: JavaScript: Test-Driven Development (ES6)
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
The purpose of unit testing3m 51s
-
(Locked)
JavaScript frameworks for unit testing2m 36s
-
(Locked)
Writing and running basic tests2m 8s
-
(Locked)
Testing basic functions5m 23s
-
(Locked)
Testing asynchronous functions3m 33s
-
(Locked)
Modifying existing functionality3m 17s
-
(Locked)
To mock or not to mock?3m 58s
-
(Locked)
Challenge: Given criteria, write unit tests3m 14s
-
(Locked)
Solution: Given criteria, write unit tests10m 29s
-
-
-
-
-
-
-