Test asynchronous callbacks with errors and return values natively in Mocha without using any plugins or third-party modules.
- [Instructor] Mocha actually supports asynchronous code…without the use of any third party plugins.…Two styles are supported,…callbacks, which have been around for a while, and promises,…which are a more modern and flexible technique.…Let's look at each and write some tests in that style.…Let's start testing callbacks with mocha.…To test a callback with mocha, add a callback to it,…which is typically named done.…When the test is complete, execute the callback.…Done can accept an error as an argument.…
Use this functionality if you don't expect an error…and it will fail if there's an error.…Our application has a good candidate…for a callback unit test.…The reservation validator uses a callback…that will populate an error and value.…The validator does not interact with the service,…and it has a consistent signature and structure.…Let's write the validator test suite.…Switch to Atom.…Make sure reservation.js is open.…Scroll past the schema test…and start the context of the validator suite,…so context('Validator'),…
- 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
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.