February 2019
Beginner
694 pages
18h 4m
English
Let's see how we can use a spy to test whether a callback function was invoked correctly. Consider the following TypeScript code:
class CallbackClass {
doCallback(id: number, callback: (result: string) => void ) {
let callbackValue = "id:" + id.toString();
callback(callbackValue);
}
}
class DoCallback {
logValue(value: string) {
console.log(value);
}
}
Firstly, we define a class named CallbackClass that has a single function, doCallback. This doCallback function takes an id argument, of type number, and also a callback function. The callback function must take a string as an argument and return void.
The second class that we have defined, named DoCallBack, has a single function, named logValue. This function ...
Read now
Unlock full access