{"action":"created","issue":{"url":"https://api.github.com/repos/caolan/forms/issues/160","labels_url":"https://api.github.com/repos/caolan/forms/issues/160/labels{/name}","comments_url":"https://api.github.com/repos/caolan/forms/issues/160/comments","events_url":"https://api.github.com/repos/caolan/forms/issues/160/events","html_url":"https://github.com/caolan/forms/issues/160","id":63865564,"number":160,"title":"obj instanceof http.IncomingMessage hard to create tests for","user":{"login":"twk-b","id":8863692,"avatar_url":"https://avatars.githubusercontent.com/u/8863692?v=3","gravatar_id":"","url":"https://api.github.com/users/twk-b","html_url":"https://github.com/twk-b","followers_url":"https://api.github.com/users/twk-b/followers","following_url":"https://api.github.com/users/twk-b/following{/other_user}","gists_url":"https://api.github.com/users/twk-b/gists{/gist_id}","starred_url":"https://api.github.com/users/twk-b/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twk-b/subscriptions","organizations_url":"https://api.github.com/users/twk-b/orgs","repos_url":"https://api.github.com/users/twk-b/repos","events_url":"https://api.github.com/users/twk-b/events{/privacy}","received_events_url":"https://api.github.com/users/twk-b/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-24T00:32:50Z","updated_at":"2015-03-24T00:51:08Z","closed_at":null,"body":"https://github.com/caolan/forms/blob/fbb4e5dc6ff93a6e8d89480aff7e278f87403915/lib/forms.js#L71\r\n            } else if (obj instanceof http.IncomingMessage) {\r\n\r\nthat line requires that you really have an instanceof http.IncomingMessage which is not really easy to create in a mock, and then randomly the code runs differently, even though you are pass something  that looks very very similar to a request ;)\r\n\r\nmaybe replace with something like: \r\n} else if (obj.body && obj.method && (obj.method === 'POST' || obj.method === 'PUT'))   {\r\n"},"comment":{"url":"https://api.github.com/repos/caolan/forms/issues/comments/85267473","html_url":"https://github.com/caolan/forms/issues/160#issuecomment-85267473","issue_url":"https://api.github.com/repos/caolan/forms/issues/160","id":85267473,"user":{"login":"ljharb","id":45469,"avatar_url":"https://avatars.githubusercontent.com/u/45469?v=3","gravatar_id":"","url":"https://api.github.com/users/ljharb","html_url":"https://github.com/ljharb","followers_url":"https://api.github.com/users/ljharb/followers","following_url":"https://api.github.com/users/ljharb/following{/other_user}","gists_url":"https://api.github.com/users/ljharb/gists{/gist_id}","starred_url":"https://api.github.com/users/ljharb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ljharb/subscriptions","organizations_url":"https://api.github.com/users/ljharb/orgs","repos_url":"https://api.github.com/users/ljharb/repos","events_url":"https://api.github.com/users/ljharb/events{/privacy}","received_events_url":"https://api.github.com/users/ljharb/received_events","type":"User","site_admin":false},"created_at":"2015-03-24T00:51:07Z","updated_at":"2015-03-24T00:51:07Z","body":"That's a strictly weaker test, that converts a prototype check to a duck type check. I'm not sure how I feel about that.\r\n\r\nTypically, mocks themselves are a code smell in tests, indicating that there's a coverage gap. However, `http.IncomingMessage` doesn't seem that hard to mock:\r\n```js\r\nvar http = require('http');\r\nvar msg = new http.IncomingMessage();\r\nmsg.method = 'POST';\r\nmsg.body = { data: true };\r\n```\r\n\r\nIn addition, please note https://github.com/caolan/forms/blob/fbb4e5dc6ff93a6e8d89480aff7e278f87403915/lib/forms.js#L82 which does require an `IncomingMessage` object."}}