I'm in the process of evaluating hapi.js. All was going well until I started writing tests. Basically I'm trying to test the status code as the first step. however I cannot proceed further. Server.inject always returns 404. I tested the same code by running the server and sending http requests using fiddler ( an http request simulation tool like postman ). This is successful. I don't know what I'm doing wrong. I'm following the exact steps as in many tutorials online. The test code is as follows.
var Lab = require("lab");
var server = require("../server/index.js").server;
var lab = exports.lab = Lab.script();
var code = require("code");
lab.test("home", function (done) {
var options = {
method: "GET",
url: "/"
}
server.inject(options, function (response) {
var result = response.result;
code.expect(response.statusCode).to.equal(200);
done();
});
});
The assertion never seems to be passing successfully, I have made sure the routes are available.
EDIT: As Matt Harrison has correctly pointed out, I'm in fact loading the routes asynchronously.
How to test in these scenarios?