Is there a way to assert the value of a property on res.locals? For example consider:
res.locals.authenticated = false;
res.render('index');
Now to test this:
expect(res.status).to.equal(200);
expect(res.locals.authenticated).to.be.false
I get a type error Cannot read property 'authenticated' of undefined
How can I test a property I pass to res.locals?
Here is the full code:
router.get('/', function (req, res) {
res.locals.authenticated = false;
res.render('index');
});
And I'm testing with Mocha, chai, and chai-http:
it('should respond with contents of the homepage', function (done) {
chai.request(server).get('/').end(function (err, res) {
expect(err).to.be.null;
expect(res.status).to.equal(200);
expect(res.locals.authenticated).to.be.false;
expect(res).to.be.html;
done();
});
});