methods icon indicating copy to clipboard operation
methods copied to clipboard

Fix error when http module is mock in tests

Open ardiadrianadri opened this issue 7 years ago • 4 comments

Hello:

Let me explain to you the problem that I am trying to solve with this PR. The problem I found is that, when I create a mock with the Jest library of Http for my unit tests, the tests fails. The reason is because the module application.js from the express library, which has a dependency on "methods", obtaining an empty array of methods ... and that ends with an exception. The problem comes because, when I make the mock of the http library with Jest, the value of * http.METHODS * is [] which it is evaluated as true and makes the function * getBasicNodeMethods * never run.

My changes are, basically, to check that he http.METHODS array exist and its length is different of 0 so, it that way, the library http can be mock for unit testing.

Regards

ardiadrianadri avatar Jan 17 '19 07:01 ardiadrianadri

Test added

ardiadrianadri avatar Jan 19 '19 19:01 ardiadrianadri