Testing Hapi Plugins

Recently, I have found myself needing to build out some authorization modules for both Hapi and Express applications. Hapi has become my server of choice, and building some fully testable plugins has been a priority. In the process, I have learned several techniques that have really streamlined my testing.

There are a few tools I’ve settled on for the baseline structure of my testing:

Test runner and base framework
Chai (Chai.expect)
Assertion library
Mocks, Stubs, Spies and many other useful helpers
Simplifies assertions against explicit routes in our server
Mocks Node’s HTTP request library for injection of responses

Continue reading →