Get the latest tech news

Test Spies in Haskell


Learn how to spy on function calls in Yesod tests using a stubbed dependency and a bit of mutable state.

Take something like a transactional email: a user signs up, resets their password, or completes a purchase — and your application needs to send a notification. Instead of calling sendEmail directly, you’ll retrieve it from somewhere that can be swapped out at runtime — like your application’s settings. This test swaps in a fake email function, triggers the handler, and checks that the expected recipient was recorded.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Haskell

Haskell

Photo of Test Spies

Test Spies

Related news:

News photo

Falsify: Hypothesis-Inspired Shrinking for Haskell (2023)

News photo

Concurrency in Haskell: Fast, Simple, Correct

News photo

Hasochism: The pleasure and pain of dependently typed Haskell programming [pdf] (2013)