Skip to content

Commit

Permalink
Add test for cached view
Browse files Browse the repository at this point in the history
  • Loading branch information
Eran Hammer committed Jul 20, 2013
1 parent 658558f commit d5bebd5
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/integration/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,12 @@ describe('Response', function () {
return request.reply.view('test.xyz', { message: "Hello World!" });
};

var cached = 1;
var cachedHandler = function (request) {

request.reply.view('test', { message: cached++ });
};

describe('Default', function (done) {

var server = new Hapi.Server({
Expand All @@ -1435,6 +1441,7 @@ describe('Response', function () {
server.route({ method: 'GET', path: '/views/insecure', config: { handler: insecureHandler } });
server.route({ method: 'GET', path: '/views/nonexistent', config: { handler: nonexistentHandler } });
server.route({ method: 'GET', path: '/views/invalid', config: { handler: invalidHandler } });
server.route({ method: 'GET', path: '/views/cache', config: { handler: cachedHandler, cache: { mode: 'server', expiresIn: 2000 } } });

it('returns a compiled Handlebars template reply', function (done) {

Expand Down Expand Up @@ -1497,6 +1504,24 @@ describe('Response', function () {
done();
});
});

it('returns a cached reply on second request', function (done) {

server.inject('/views/cache', function (res) {

expect(res.result).to.exist;
expect(res.result).to.equal('<div>\n <h1>1</h1>\n</div>\n');
expect(res.statusCode).to.equal(200);

server.inject('/views/cache', function (res) {

expect(res.result).to.exist;
expect(res.result).to.equal('<div>\n <h1>1</h1>\n</div>\n');
expect(res.statusCode).to.equal(200);
done();
});
});
});
});

describe('Layout', function (done) {
Expand Down

0 comments on commit d5bebd5

Please sign in to comment.