flâneur

nodebestpractices/sections/testingandquality/test-middlewares.md at master · goldbergyoni/nodebestpractices

github.com · 191 words · saved by 1 readers

:white_check_mark: The Node.js best practices list (July 2024) - goldbergyoni/nodebestpractices

Test your middlewares in isolation One Paragraph Explainer Many avoid Middleware testing because they represent a small portion of the system and require a live Express server. Both reasons are wrong — Middlewares are small but affect all or most of the requests and can be tested easily as pure functions that get {req,res} JS objects. To test a middleware function one should just invoke it and spy (using Sinon for example) on the interaction with the {req,res} objects to ensure the function performed the right action. The library node-mock-http takes it even further and factors the…

saved by

related reading