Skip to content

Instantly share code, notes, and snippets.

@searls
Created December 23, 2017 14:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save searls/d09acbeff4978aac4ca661efa3c77d40 to your computer and use it in GitHub Desktop.
Save searls/d09acbeff4978aac4ca661efa3c77d40 to your computer and use it in GitHub Desktop.
Discovery testing example: rewriting td.verify()

I'm currently undergoing a 9-month-long in-place rewrite of testdouble.js (which has proven to be a really stupid idea, but mildly entertaining at least).

This morning, my goal was to break down the responsibilities of the totally not unit-tested td.verify() function with a number of smaller modules which are test-driven with an outside-in approach.

I get a bunch of questions about how I "actually" do this, so I logged each step I took in a separate commit. You can see the 9 steps I took, including the final step—realizing that the contract I'd created was not how I wanted, refactoring one of the dependencies' contracts before it had even been written!

  1. Psuedo code the module with comments to start shaking out desirable names of dependencies
  2. Define those dependencies in a test (and then making that test pass by creating the modules)
  3. Write the first failing test of the happy path behavior
  4. Make the first test pass
  5. Write the second failing test of the failure path
  6. Make the second test pass
  7. Write the final test of the guard clause
  8. Realizing ES destructuring didn't behave how I expected when that test unexpectedly failed, make the final test pass
  9. In response to that surprise, refactor the design to smooth out the ugly workaround

Being able to get critical feedback about my dependencies' relationships before I've invested the time into actually writing them has proven an incredibly valuable time saver over the years, and one of my favorite benefits of outside-in test-driven development

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment