I tried the official documentation but I could not find out how to check is a given middleware (i.e. morgan) is being used by the current application. Since my middleware configuration depends on development/production situation, I would like to check for them being active within my mocha tests
相关问题
- Axios OPTIONS instead of POST Request. Express Res
- Express js optional parameter
- ExpressJS: Promises and Error Handling middleware
- Sequelize where on many-to-many join
- Correct headers, but Chrome says “Resource interpr
相关文章
- fetch: Getting cookies from fetch response
- express server port configuration issue with pm2 c
- why is socket.id undefined in the browser
- What is describe() in Mocha
- Using HTTP basic auth for certain URLs only with E
- node express: should you always call next() in a g
- Express redirect error: can't set headers afte
- Django: What is the most ideal place to store proj
Express doesn't allow for this very cleanly.
The best you can do is to look at
app._router.stack
, specifically at the function references, or if that's not possible, the name of the functions:So, I recommend a slightly different approach. If you can get a reference to the middleware function you expect your app to
use
, you can stubuse
and assert on what was passed.(pseudo-code-ish)
Hope that's somewhat illustrative. The point is to inject things so that you don't need to assert on the actual express app itself, you can just inject mock objects and do your assertions based on those.