eugef / node-mocks-http

Mock 'http' objects for testing Express routing functions
Other
755 stars 134 forks source link

How can I set res.locals? #132

Closed takehilo closed 7 years ago

takehilo commented 7 years ago

My production code is like the following:

res.locals.flash = {
  type: 'danger',
  message: 'error'
};

res.status(400)
return res.render('index');

How can I set res.locals using httpMocks.createResponse? It would be nice if I could set any property as httpMocks.createRequest does:

httpMocks.createResponse({
  locals: {}
});

Thank you.

takehilo commented 7 years ago

A simple way is just adding locals property but are there any other ways to do this?

const res = httpMocks.createResponse();
res.locals = {};
howardabrams commented 7 years ago

Hopefully, version 1.6.2 will solve your problem.

eugef commented 6 years ago

Version 1.6.6 si still missing this feature

eugef commented 6 years ago

Version > 1.6.6 should have this fixed