Hapi is a very solid framework that makes writing maintainable and testable web servers so much easier than, say, Express, that I'm seriously considering flying to Los Gatos just to buy @eranhammer a beer.

There's just this one thing bothering me. If you're using Mocha, no doubt you'll very soon come across #1299 - exceptions thrown in server.inject do not propagate.

In other words code like this:

it('should fail with a descriptive error', function(done) {
  server.inject({method: 'GET', url: '/chuck'}, function (res) {
    expect(true).to.be.false;
    done();
  });
});

will just timeout instead of reporting expected true to be false. Which pretty much means testing hapi with mocha sucks.

Now I know the issue's on Mocha side and I know there's lab and I'm sure it's awesome, great and, well, just made of candy. But I already know and like mocha. And I don't want to switch, ain't nobody got time for that.

Luckily, there's a workaround! Enter bendrucker's inject-then plugin (mentioned in the GH issue) allowing us to treat inject as a promiseful method. Register it as a plugin in your tests...

server.register([
  {register: require('inject-then')},
  // ... other plugins ...
]);

...and propagate mocha errors out of injectThen as a pro!

it('should fail with a descriptive error', function(done) {
  return server.injectThen({method: 'GET', url: '/chuck'})
    .then(function(res) {
      expect(true).to.be.false;
    });
});

Promises and descriptive test failures: in my book a win-win. Thanks, @bendrucker!

Happy, uh, ummm, hapiying? (Want to suggest a better verb? I'm @tomas_brambora)