Skip to content

Commit

Permalink
tests: add test for typical model usage
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Mar 17, 2020
1 parent a9dbdc2 commit da7edaf
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
unreleased
==========

* deps: handlebars@4.7.4

4.1.0 / 2020-01-14
==================

Expand Down
28 changes: 28 additions & 0 deletions test/3.x/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ before(function () {
})
})

app.get('/locals-model', function (req, res) {
res.locals.person = new Person('Alan', 'Smith')
res.render('locals', {
layout: false,
kids: [new Person('Jimmy', 'Smith'), new Person('Sally', 'Smith')]
})
})

app.get('/globals', function (req, res) {
res.render('globals', {
layout: 'layout_globals',
Expand Down Expand Up @@ -258,6 +266,13 @@ test('response locals cached', function(done) {
})
});

test('response locals model', function(done) {
request(app)
.get('/locals-model')
.expect(fs.readFileSync(path.join(FIXTURES_DIR, 'locals.html'), 'utf8'))
.end(done)
});

test('response globals', function(done) {
request(app)
.get('/globals')
Expand All @@ -278,3 +293,16 @@ function shouldHaveFirstLineEqual (str) {
assert.strictEqual(res.text.split(/\r?\n/)[0], str)
}
}

function Person (firstName, lastName) {
this.firstName = firstName
this.lastName = lastName
}

Person.prototype.toString = function toString () {
return this.name()
}

Person.prototype.name = function name () {
return this.firstName
}
28 changes: 28 additions & 0 deletions test/4.x/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ before(function () {
})
})

app.get('/locals-model', function (req, res) {
res.locals.person = new Person('Alan', 'Smith')
res.render('locals', {
layout: false,
kids: [new Person('Jimmy', 'Smith'), new Person('Sally', 'Smith')]
})
})

app.get('/globals', function (req, res) {
res.render('globals', {
layout: 'layout_globals',
Expand Down Expand Up @@ -280,6 +288,13 @@ test('response locals cached', function(done) {
})
});

test('response locals model', function(done) {
request(app)
.get('/locals-model')
.expect(fs.readFileSync(path.join(FIXTURES_DIR, 'locals.html'), 'utf8'))
.end(done)
});

test('response globals', function(done) {
request(app)
.get('/globals')
Expand Down Expand Up @@ -307,3 +322,16 @@ function shouldHaveFirstLineEqual (str) {
assert.strictEqual(res.text.split(/\r?\n/)[0], str)
}
}

function Person (firstName, lastName) {
this.firstName = firstName
this.lastName = lastName
}

Person.prototype.toString = function toString () {
return this.name()
}

Person.prototype.name = function name () {
return this.firstName
}

0 comments on commit da7edaf

Please sign in to comment.