expect

abstract suspend fun <T> expect(urlPattern: Regex, block: suspend RequestExpectation.() -> T): T

Expects a request to match the given urlPattern.

For example, capturing the response body of a specific API call can be done like this:

val responseBody = tab.expect(Regex("https://api.example.com/data")) {
tab.get("https://example.com")
getResponseBody<UserData>()
}

Parameters

urlPattern

The regex pattern to match the request URL.

block

The block to execute during which the expectation is active.