express-mock-request icon indicating copy to clipboard operation
express-mock-request copied to clipboard

express.methods() no longer available

Open seldo opened this issue 12 years ago • 4 comments

The line

methods = require('express').methods

in index.js fails against the most recent version of Express. I can get this module to work fine by simply hard-coding an array ['get','post',..] etc. but is there some better way to do this now? I note this repo has not been updated in a while.

seldo avatar Jun 10 '13 03:06 seldo

More detailed example of a work-around. I added this to to the top of my test file:

var express = require('express');
express.methods = [ 'get', 'post', 'delete' ]; 

jmervine avatar Jun 10 '13 21:06 jmervine

I thought this was merged into the main repo, but having the same issue myself...

matogertel avatar Dec 09 '13 02:12 matogertel

also still having the issue

MiniXC avatar Aug 13 '16 19:08 MiniXC

The README for this project states that the code came from the express test suites. The link it provides is now broken, but looking into the test suites it looks like they now use supertest (or at least there are tests that use supertest). That library is somewhat different as it actually listens on a port and sends a real HTTP request (if I understand correctly).

However, for me that serves my purpose, as I only want a small number of tests at this level, as I'm testing express middleware that will delegate to other functions that I can unit test in isolation. (I'd suggest that anyone who has a reason to look for mock request objects consider whether they can have a thin layer that extracts the data they need from the request object and pass just that extracted data on to other simpler functions that are easier to test. Then you only need a small number of tests to test that thin layer. Of course there will be exceptions though...)

neocolmartin avatar May 18 '17 13:05 neocolmartin