seanpmaxwell/overnight

Testing

Closed this issue · 4 comments

bmax commented

Hey @seanpmaxwell,

Awesome piece of code ya have here. We're using it in Production and it's all great. We're trying to figure out how to test the controllers/middlewares with Jest. Any good advice? So far the only way I can do it is make the method public and mock a request/response but that doesn't do any good for the Middleware decorator.

Let me know if I can help with a PR if you have any ideas.

Thanks,
Brandon.

I've never used Jest on the back-end so I can't advise on it. I'm a huge fan of the Jasmine/SuperTest combo though. It's pretty straightforward. You just need to add the instance of express the to supertest agent method. I wrote an article on how to do this: https://levelup.gitconnected.com/setting-up-a-full-stack-typescript-application-featuring-express-and-react-ccfe07f2ea47. Scroll down to the section on unit-testing.

bmax commented

@seanpmaxwell Thanks! That looks like it's super useful for end-to-end testing. I'm looking for more just shallow unit testing. The test server concept might help me with that though. Let me give it another try.

No this IS for unit-testing not e2e.

bmax commented

Thanks @seanpmaxwell this helps a ton.