{"action":"created","issue":{"url":"https://api.github.com/repos/jhnns/rewire/issues/56","labels_url":"https://api.github.com/repos/jhnns/rewire/issues/56/labels{/name}","comments_url":"https://api.github.com/repos/jhnns/rewire/issues/56/comments","events_url":"https://api.github.com/repos/jhnns/rewire/issues/56/events","html_url":"https://github.com/jhnns/rewire/issues/56","id":69479496,"number":56,"title":"Object.defineProperty called on non-object with mocha","user":{"login":"MitMaro","id":177427,"avatar_url":"https://avatars.githubusercontent.com/u/177427?v=3","gravatar_id":"","url":"https://api.github.com/users/MitMaro","html_url":"https://github.com/MitMaro","followers_url":"https://api.github.com/users/MitMaro/followers","following_url":"https://api.github.com/users/MitMaro/following{/other_user}","gists_url":"https://api.github.com/users/MitMaro/gists{/gist_id}","starred_url":"https://api.github.com/users/MitMaro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MitMaro/subscriptions","organizations_url":"https://api.github.com/users/MitMaro/orgs","repos_url":"https://api.github.com/users/MitMaro/repos","events_url":"https://api.github.com/users/MitMaro/events{/privacy}","received_events_url":"https://api.github.com/users/MitMaro/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-20T00:18:18Z","updated_at":"2015-04-23T02:08:45Z","closed_at":null,"body":"## Description\r\nI believe that may be related to #51 given it produces the same error.\r\n\r\nWhen using mocha and rewire with a module that exports a named function directly, an error occurs:\r\n\r\n    TypeError: Object.defineProperty called on non-object\r\n\r\nRunning without mocha and using node directly works correctly.\r\n\r\nChanging from a named function to assigning the function *(see test files below)* and exporting the variable instead works.\r\n\r\n#### Example\r\n```javascript\r\nvar foo = function () {};\r\nmodule.exports = foo;\r\n```\r\n\r\n## Test Files\r\n#### index.js\r\n```javascript\r\nvar rewire = require('rewire');\r\nvar test = rewire('./test');\r\n```\r\n#### test.js\r\n```\r\nfunction run() {}\r\nmodule.exports = run;\r\n```\r\n\r\n#### Gist\r\nhttps://gist.github.com/MitMaro/eb09a24817bcc58f9421\r\n\r\n###### Running\r\nnpm install\r\nmocha index.js\r\n\r\n## Stacktrace\r\n\r\n\t/Users/mitmaro/Code/rewire.mocha.bug/test.js:4\r\n\tObject.defineProperty(module.exports, '__get__', {enumerable: false, value: fu\r\n\t\t   ^\r\n    TypeError: Object.defineProperty called on non-object\t\r\n\t\tat Function.defineProperty (native)\r\n\t\tat Object.<anonymous> (/Users/mitmaro/Code/rewire.mocha.bug/test.js:4:8)\r\n\t\tat Module._compile (module.js:446:26)\r\n\t\tat Object.Module._extensions..js (module.js:464:10)\r\n\t\tat Module.load (module.js:341:32)\r\n\t\tat Object.load (/Users/mitmaro/Code/rewire.mocha.bug/node_modules/rewire/lib/moduleEnv.js:19:18)\r\n\t\tat internalRewire (/Users/mitmaro/Code/rewire.mocha.bug/node_modules/rewire/lib/rewire.js:50:15)\r\n\t\tat rewire (/Users/mitmaro/Code/rewire.mocha.bug/node_modules/rewire/lib/index.js:11:12)\r\n\t\tat Object.<anonymous> (/Users/mitmaro/Code/rewire.mocha.bug/index.js:2:12)\r\n\t\tat Module._compile (module.js:446:26)\r\n\t\tat Object.Module._extensions..js (module.js:464:10)\r\n\t\tat Module.load (module.js:341:32)\r\n\t\tat Function.Module._load (module.js:296:12)\r\n\t\tat Module.require (module.js:351:17)\r\n\t\tat require (module.js:370:17)\r\n\t\tat /Users/mitmaro/Code/rewire.mocha.bug/node_modules/mocha/lib/mocha.js:192:27\r\n\t\tat Array.forEach (native)\r\n\t\tat Mocha.loadFiles (/Users/mitmaro/Code/rewire.mocha.bug/node_modules/mocha/lib/mocha.js:189:14)\r\n\t\tat Mocha.run (/Users/mitmaro/Code/rewire.mocha.bug/node_modules/mocha/lib/mocha.js:422:31)\r\n\t\tat Object.<anonymous> (/Users/mitmaro/Code/rewire.mocha.bug/node_modules/mocha/bin/_mocha:398:16)\r\n\t\tat Module._compile (module.js:446:26)\r\n\t\tat Object.Module._extensions..js (module.js:464:10)\r\n\t\tat Module.load (module.js:341:32)\r\n\t\tat Function.Module._load (module.js:296:12)\r\n\t\tat Function.Module.runMain (module.js:487:10)\r\n\t\tat startup (node.js:111:16)\r\n\t\tat node.js:799:3\r\n"},"comment":{"url":"https://api.github.com/repos/jhnns/rewire/issues/comments/95391812","html_url":"https://github.com/jhnns/rewire/issues/56#issuecomment-95391812","issue_url":"https://api.github.com/repos/jhnns/rewire/issues/56","id":95391812,"user":{"login":"MitMaro","id":177427,"avatar_url":"https://avatars.githubusercontent.com/u/177427?v=3","gravatar_id":"","url":"https://api.github.com/users/MitMaro","html_url":"https://github.com/MitMaro","followers_url":"https://api.github.com/users/MitMaro/followers","following_url":"https://api.github.com/users/MitMaro/following{/other_user}","gists_url":"https://api.github.com/users/MitMaro/gists{/gist_id}","starred_url":"https://api.github.com/users/MitMaro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MitMaro/subscriptions","organizations_url":"https://api.github.com/users/MitMaro/orgs","repos_url":"https://api.github.com/users/MitMaro/repos","events_url":"https://api.github.com/users/MitMaro/events{/privacy}","received_events_url":"https://api.github.com/users/MitMaro/received_events","type":"User","site_admin":false},"created_at":"2015-04-23T02:08:44Z","updated_at":"2015-04-23T02:08:44Z","body":"I noticed the issue I had linked was the incorrect one. It's been fixed."}}