HTTP Mocking Made Easy With Nock

I love testing and I love small easily testable modules in Node.

Recently I had to build a library module that interacts with some web services via HTTP.

To test this module as it was would mean that I would have to have a sandboxed account on the other end. I also would have to have setup and teardown routines that would reset the sandbox to a known state, etc, etc.

What I really wanted for the unit tests was to test the module in isolation. In this case, it would mean capturing the HTTP requests and replying a pre-made response.