Test asynchronous promises in Mocha natively without using the plugin chai-as-promised by placing assertions in then and catch statements.
- [Instructor] We've tested callbacks with mocha,…but that's not the only kind of asynchronous code.…What about promises?…Mocha supports Promises natively,…which is a great feature.…To test a promise, just return the promise…and put the assertion in the .then or .catch.…You do not need to use the callback named done().…If you do, it'll throw an error…because it's usually a mistake.…What about the plugin chai-as-promised?…Isn't that required?…Not as of mocha version 3.0.0. and above.…
You can still use it if you'd like,…if you'd like a more readable assertion,…but it's completely optional now.…Alright, so, what should we be testing?…We haven't seen any code yet with promises.…Let's switch over to Atom.…Let's close the tabs by right-clicking…and going to Close All Tabs,…then selecting reservations.js over in the tree-view.…This file is a library of operations…on multiple reservations.…All of the functions return promises,…but the first three use the database, like getAll,…create uses the database, save uses the database,…
- What is code quality?
- Testing and code quality fundamentals
- Coding conventions and standards
- Creating and enforcing coding standards
- Unit, integration, and functional testing
- Test-driven development test specificatons
- Behavior-driven development test specifications
- Finding errors with linting
- Extending an ESLint shareable config
- Validating correctness with unit testing
- Replacing and inspecting with stubs, spies, and mocks
- Code coverage and why it matters
- Coverage with continuous integration
Skill Level Intermediate
Node.js: Build Your First Microservicewith Daniel Khan2h 9m Intermediate
Building APIs Using Hapi in Node.jswith Kirsten Hunter2h 23m Intermediate
Node.js: Extend and Maintain Applicationswith Daniel Khan3h 35m Intermediate
1. Testing and Code Quality Fundamentals
2. Finding Errors with Linting
3. Validating Correctness with Unit Testing
4. Replacing and Inspecting with Stubs, Spies, and Mocks
5. Reporting on Your Entire Codebase
Where to go from here?3m 46s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.