Reading Class 03 - meron-401n14/seattle-javascript-401n14 GitHub Wiki
Understanding Error-First Callbacks
When using Node.js with Google v8 engine then callbacks are very important. Calbacks enable the non-blocking of asynchronous control flow of applications and modules. For callbacks to be efficient you need a protocol called error-first callbacks so that applications can be scaled effectively. Callbacks have been standardize over the years so that when they are passed as an argument to be called once the rest of that code has been run. This allows different functions to asynchronously hand control back and forth across an application.
DEFINING AN ERROR-FIRST CALLBACK
There’s really only two rules for defining an error-first callback: The first argument of the callback is reserved for an error object. If an error occurred, it will be returned by the first err argument. The second argument of the callback is reserved for any successful response data. If no error occurred, err will be set to null and any successful data will be returned in the second argument.
Understanding Jest Mocks
Mocking is a technique to isolate test subjects by replacing dependencies with objects that you can control and inspect. A dependency can be anything your subject depends on, but it is typically a module that the subject imports.When we talk about mocking in Jest, we’re typically talking about replacing dependencies with the Mock Function.
The Mock Function
The goal for mocking is to replace something we don’t control with something we do, so it’s important that what we replace it with has all the features we need.