{"action":"created","issue":{"url":"https://api.github.com/repos/pgte/nock/issues/335","labels_url":"https://api.github.com/repos/pgte/nock/issues/335/labels{/name}","comments_url":"https://api.github.com/repos/pgte/nock/issues/335/comments","events_url":"https://api.github.com/repos/pgte/nock/issues/335/events","html_url":"https://github.com/pgte/nock/issues/335","id":87298562,"number":335,"title":"Nock + Osmosis support","user":{"login":"matiassingers","id":938453,"avatar_url":"https://avatars.githubusercontent.com/u/938453?v=3","gravatar_id":"","url":"https://api.github.com/users/matiassingers","html_url":"https://github.com/matiassingers","followers_url":"https://api.github.com/users/matiassingers/followers","following_url":"https://api.github.com/users/matiassingers/following{/other_user}","gists_url":"https://api.github.com/users/matiassingers/gists{/gist_id}","starred_url":"https://api.github.com/users/matiassingers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matiassingers/subscriptions","organizations_url":"https://api.github.com/users/matiassingers/orgs","repos_url":"https://api.github.com/users/matiassingers/repos","events_url":"https://api.github.com/users/matiassingers/events{/privacy}","received_events_url":"https://api.github.com/users/matiassingers/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-06-11T10:38:59Z","updated_at":"2015-06-11T12:38:47Z","closed_at":"2015-06-11T12:38:47Z","body":"I wasn't really sure where I should create this issue, so I created it on both projects. See https://github.com/rc0x03/node-osmosis/issues/33\r\n\r\n----\r\n\r\nI'm facing some issues using [Osmosis] and [Nock] for mocking HTTP responses in my unit tests, see the build failing on [Travis](https://travis-ci.org/matiassingers/spotify-countries). The `before` timeout in mocha gets triggered because [Osmosis] is encountering an error in the request/parsing.\r\n\r\nI've written the smallest reproducible test case I could come up with, based on the failing build above.\r\n\r\n### test case\r\n```js\r\nvar osmosis = require('osmosis');\r\nvar nock = require('nock');\r\n\r\nnock('https://www.spotify.com')\r\n  .get('/select-your-country/')\r\n  .reply(200, 'whatever');\r\n\r\nosmosis\r\n  .get('https://www.spotify.com/select-your-country/')\r\n  .find('.country-list .country-item .country-link')\r\n  .set({\r\n    countryCode: '@rel'\r\n  })\r\n  .error(console.error)\r\n  .done(function(){\r\n    // never reaches here :sadface:\r\n    console.log('it works!');\r\n  });\r\n```\r\n\r\n### error\r\n```sh\r\n(get) TypeError: Cannot read property '_hasBody' of undefined\r\n[get] https://www.spotify.com/select-your-country/ tries: 1 - Cannot read property '_hasBody' of undefined\r\n    at /Users/matiassingers/dev/osmosis-nock-5226/node_modules/osmosis/index.js:150:35\r\n    at done (/Users/matiassingers/dev/osmosis-nock-5226/node_modules/osmosis/node_modules/needle/lib/needle.js:355:7)\r\n    at PassThrough.<anonymous> (/Users/matiassingers/dev/osmosis-nock-5226/node_modules/osmosis/node_modules/needle/lib/needle.js:523:9)\r\n    at PassThrough.emit (events.js:117:20)\r\n    at _stream_readable.js:943:16\r\n    at process._tickCallback (node.js:419:13)\r\n```\r\n\r\n### possible bug\r\nThe offending lines in [Osmosis] look like this:\r\n```js\r\nif (!res.socket._httpMessage._hasBody || data.length == 0)\r\n  throw(new Error('Document is empty'))\r\n```\r\n\r\n`res.socket` contains no `_httpMessage` property when returning the mocked response from [Nock], this is the entire object:\r\n```js\r\n{ domain: null,\r\n  _events: {},\r\n  _maxListeners: 10,\r\n  writable: true,\r\n  readable: true,\r\n  setNoDelay: [Function: noop],\r\n  setTimeout: [Function],\r\n  _checkTimeout: [Function],\r\n  setKeepAlive: [Function: noop],\r\n  destroy: [Function: noop],\r\n  resume: [Function: noop],\r\n  getPeerCertificate: [Function: getPeerCertificate] }\r\n```\r\n\r\n----\r\n\r\nThe question then is:\r\n- Is [Nock] mocking the requests wrongly by not including the `_httpMessage._hasBody` property?\r\n- Or shouldn't [Osmosis] be checking for this property at all? Might be deprecated or something.\r\n\r\n\r\n[Osmosis]: https://github.com/rc0x03/node-osmosis\r\n[Nock]: https://github.com/pgte/nock"},"comment":{"url":"https://api.github.com/repos/pgte/nock/issues/comments/111118001","html_url":"https://github.com/pgte/nock/issues/335#issuecomment-111118001","issue_url":"https://api.github.com/repos/pgte/nock/issues/335","id":111118001,"user":{"login":"matiassingers","id":938453,"avatar_url":"https://avatars.githubusercontent.com/u/938453?v=3","gravatar_id":"","url":"https://api.github.com/users/matiassingers","html_url":"https://github.com/matiassingers","followers_url":"https://api.github.com/users/matiassingers/followers","following_url":"https://api.github.com/users/matiassingers/following{/other_user}","gists_url":"https://api.github.com/users/matiassingers/gists{/gist_id}","starred_url":"https://api.github.com/users/matiassingers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matiassingers/subscriptions","organizations_url":"https://api.github.com/users/matiassingers/orgs","repos_url":"https://api.github.com/users/matiassingers/repos","events_url":"https://api.github.com/users/matiassingers/events{/privacy}","received_events_url":"https://api.github.com/users/matiassingers/received_events","type":"User","site_admin":false},"created_at":"2015-06-11T12:38:47Z","updated_at":"2015-06-11T12:38:47Z","body":"@pgte thanks for your quick response! Yeah I though the checking of private properties looked wrong as well, I'll close this issue and continue it on the Osmosis repo.\r\n\r\nThanks!"}}