sinon-express-mock
sinon-express-mock copied to clipboard
Persist mutations to locals
Locals can not currently be mutated after their assignment. This causes issues when testing the following:
const middleware = (req, res, next) => {
res.locals.myVar = "new";
next();
};
const req = mockReq();
const res = mockRes({ locals: { myVar: "old" } });
middleware(req, res, spy());
res.locals.myVar // "old"
This is useful to test as some middleware can be reliant on previous middleware setting locals (such as decoding tokens).
@danawoodman I noticed from https://github.com/danawoodman/sinon-express-mock/issues/12 that you mentioned you're not actively maintaining this repo anymore, in which case I'll get around to this when I get a chance. Otherwise if anyone else notices this I'm happy for them to pick this up.
Yeah, the mocking is pretty "dumb" and doesn't handle locals well. Very happy for a PR 👍