Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persist mutations to locals #17

Open
alexandradeas opened this issue Jan 29, 2019 · 1 comment
Open

Persist mutations to locals #17

alexandradeas opened this issue Jan 29, 2019 · 1 comment

Comments

@alexandradeas
Copy link

alexandradeas commented Jan 29, 2019

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 #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.

@alexandradeas alexandradeas changed the title Reflect mutations to locals Persist mutations to locals Jan 29, 2019
@danawoodman
Copy link
Owner

Yeah, the mocking is pretty "dumb" and doesn't handle locals well. Very happy for a PR 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants