Chapter 3Test Asynchrony

JavaScript libraries are filled with async functions. For example, to read a file, give the filename to the fs library and it’ll get back later with data or an error. Likewise, talking to services involves async functions—we can’t escape asynchrony. Let’s embrace asynchrony with automated tests.

Writing and executing automated tests for asynchronous functions poses some challenges. A call to a synchronous function blocks and waits for the result. However, a call to an asynchronous function is nonblocking and the result or error will arrive later through callbacks or promises. To write automated verifications for async functions, you need to go beyond the techniques you learned in the previous chapter.

Let’s ...

Get Test-Driving JavaScript Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.