有没有办法在res.locals上声明属性的值?例如,考虑:
res.locals.authenticated = false;
res.render('index');
现在测试一下:
expect(res.status).to.equal(200);
expect(res.locals.authenticated).to.be.false
我收到类型错误无法读取属性'已验证'未定义的
如何测试我传递给res.locals的属性?
以下是完整代码:
router.get('/', function (req, res) {
res.locals.authenticated = false;
res.render('index');
});
我正在测试Mocha,chai和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();
});
});