February 2019
Beginner
694 pages
18h 4m
English
The asynchronous nature of JavaScript—made popular by AJAX and jQuery—has always been one of the draw-cards of the language, and is the principal architecture behind Node-based applications. Let's take a quick look at an asynchronous class, and then describe how we should go about testing it. Consider the following TypeScript code:
class MockAsyncClass {
executeSlowFunction(success: (value: string) => void) {
setTimeout(() => {
success("success");
}, 1000);
}
}
This MockAsyncClass has a single function, named executeSlowFunction, which takes a function callback named success. Within the executeSlowFunction code, we are simulating an asynchronous call with the setTimeout function, and only calling the success callback ...
Read now
Unlock full access