danawoodman / sinon-express-mock

Simple request and response mock objects to pass into Express routes when testing using Sinon.

Home Page:https://www.npmjs.com/package/sinon-express-mock

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mocked next?

OmgImAlexis opened this issue · comments

What's the recommended way to handle routes that use next for error handling?

@OmgImAlexis You should be able to just drop in a spy/stub to mock next as the function doesn't have any functionality that's local to the middleware. Instead it notifies express to call the next RequestHandler or ErrorRequestHandler

@alex-deas is correct, just create a const next = sinon.mock() or whatever and pass it in!