Examples
Real tests, start to finish
Each example is a test from Understudy's own suite, which builds and passes in CI. Read the short story of what it checks, then copy the test.
let heldRefresh = tokenRoute.holdNextCall()
A server error reaches the client as its own error
A 503 from /me becomes APIError.serviceUnavailable in the app.
server.route(.get, "/me").willReturn(.status(503))
A spy keeps every call, in order
Call the double twice, then read what it was called with.
#expect(catalog.productSpy.calls == expectedIDs)
One answer per argument
A lamp for id 1, a chair for anything over 100, nil for the rest.
catalog.productSpy.willReturn(.lamp, for: 1)
Save before sending
Watch two doubles with one CallOrder and check the order the code called them in.
#expect(order.names == expectedOrder)
Checkout is tracked, with two views
Give the analytics spy expectations and the test fails on a missing or extra event.
analytics.trackSpy.expect("checkout")
Greets by name once the clock passes the delay
A 400 ms sleep passes in no real time with TestClock.
await clock.advance(by: .milliseconds(400))
A free product in one line
The test names the price and its tags, and nothing else.
let free = Product.sample(price: 0, tags: tags)
No example matches. Try another word or tool.