Chapter 13
Testing Network Responses (and Closures)

In the previous chapter, we saw a way to test network requests. These tests confirm that we’re sending the expected network calls. But we also want to test how to handle network responses, from the “happy path” to error cases.

Response handling is commonly done with closures. Since closures are like code hidden inside of code, how can we test them?

In this chapter you’ll learn how to test closures. This will give you a way to test all kinds of network responses, including errors that are normally hard to reproduce. You’ll also learn how to test asynchronous code that crosses threads.