Skip to content

Instantly share code, notes, and snippets.

@saml
Created December 4, 2020 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saml/7d134428c7feeb94ddf21fc7383a62fc to your computer and use it in GitHub Desktop.
Save saml/7d134428c7feeb94ddf21fc7383a62fc to your computer and use it in GitHub Desktop.
function runMiddleware(middleware, req, res) {
return new Promise((resolve, reject) => {
function next(value) {
if (value instanceof Error) {
reject(value);
} else {
resolve(value);
}
}
middleware(req, res, next);
});
}
// in tests
await runMiddleware(myMiddleware, reqMock, resMock);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment