Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when http module is mock in tests #20

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ module.exports = getCurrentNodeMethods() || getBasicNodeMethods()
*/

function getCurrentNodeMethods () {
return http.METHODS && http.METHODS.map(function lowerCaseMethod (method) {
var methods = http.METHODS && http.METHODS.map(function lowerCaseMethod (method) {
return method.toLowerCase()
})

return (methods && methods.length > 0) ? methods : false
}

/**
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"scripts": {
"lint": "eslint .",
"test": "mocha --reporter spec --bail --check-leaks test/",
"test-debug": "mocha --inspect-brk test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
},
Expand Down
48 changes: 46 additions & 2 deletions test/methods.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var http = require('http')
var assert = require('assert')
var methods = require('..')

describe('methods', function () {
var http = require('http')
var methods = require('..')
if (http.METHODS) {
it('is a lowercased http.METHODS', function () {
var lowercased = http.METHODS.map(function (method) {
Expand All @@ -25,3 +25,47 @@ describe('methods', function () {
})
}
})

describe('empty methods', function () {
it('should get the default methods if http.METHODS === []', function () {
delete require.cache[require.resolve('http')]
delete require.cache[require.resolve('..')]
var http = require('http')
http.METHODS = []
var defaultMethods = require('..')
var defaultValues = [
'get',
'post',
'put',
'head',
'delete',
'options',
'trace',
'copy',
'lock',
'mkcol',
'move',
'purge',
'propfind',
'proppatch',
'unlock',
'report',
'mkactivity',
'checkout',
'merge',
'm-search',
'notify',
'subscribe',
'unsubscribe',
'patch',
'search',
'connect'
]
var leng = defaultMethods.length
assert.equal(defaultMethods.length, defaultValues.length)

for (var i = 0; i < leng; i++) {
assert.equal(defaultMethods[i], defaultValues[i])
}
})
})