I am currently testing express middleware using sinon.js
My goal is to verify that it sends a specific JSON response and prevents the request from moving on to the next middleware or request handler.
const middleware = (req: Request, res: Response, next: NextFunction) => {
setTimeout(() => res.json({status: 'blocked'}), 1000);
}
To mock the Request and Response objects, I am utilizing sinon-express-mock
. This allows me to have every property and method in the Response object as a SinonStub
.
The issue I am encountering is that when I invoke the middleware and the json
method is triggered, I am unsure how to check it afterwards.
Is there a listener or observer available for SinonStub?
Thank you.