{"action":"created","issue":{"url":"https://api.github.com/repos/jhnns/rewire/issues/48","labels_url":"https://api.github.com/repos/jhnns/rewire/issues/48/labels{/name}","comments_url":"https://api.github.com/repos/jhnns/rewire/issues/48/comments","events_url":"https://api.github.com/repos/jhnns/rewire/issues/48/events","html_url":"https://github.com/jhnns/rewire/issues/48","id":63209459,"number":48,"title":"TypeError: Cannot read property '0' of undefined","user":{"login":"phun-ky","id":1714029,"avatar_url":"https://avatars.githubusercontent.com/u/1714029?v=3","gravatar_id":"","url":"https://api.github.com/users/phun-ky","html_url":"https://github.com/phun-ky","followers_url":"https://api.github.com/users/phun-ky/followers","following_url":"https://api.github.com/users/phun-ky/following{/other_user}","gists_url":"https://api.github.com/users/phun-ky/gists{/gist_id}","starred_url":"https://api.github.com/users/phun-ky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phun-ky/subscriptions","organizations_url":"https://api.github.com/users/phun-ky/orgs","repos_url":"https://api.github.com/users/phun-ky/repos","events_url":"https://api.github.com/users/phun-ky/events{/privacy}","received_events_url":"https://api.github.com/users/phun-ky/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-03-20T11:04:50Z","updated_at":"2015-03-24T13:49:55Z","closed_at":null,"body":"I'm using karma-runner to run jasmine tests, with the setup below.\r\n\r\nI'm getting this error when launching karma:\r\n\r\n    Chrome 41.0.2272 (Linux) ERROR\r\n    Uncaught TypeError: Cannot read property '0' of undefined  at tmp/cc96bc0f13c8df482b64e5d6150bb474.browserify:27303:0 <- ../../../../../../node_modules/rewire/lib/moduleEnv.js:7:0\r\n\r\n\r\nkarma.conf.js: https://gist.github.com/phun-ky/8dbc66b211c718252e58\r\n\r\nRewire module from http://substantial.com/blog/2014/11/11/test-driven-react-how-to-manually-mock-components/ :\r\n    var rewireModule = function rewireModule(rewiredModule, varValues) {\r\n      var rewiredReverts = [];\r\n\r\n      beforeEach(function() {\r\n        var key, value, revert;\r\n        for (key in varValues) {\r\n          if (varValues.hasOwnProperty(key)) {\r\n            value = varValues[key];\r\n            revert = rewiredModule.__set__(key, value);\r\n            rewiredReverts.push(revert);\r\n          }\r\n        }\r\n      });\r\n\r\n      afterEach(function() {\r\n        rewiredReverts.forEach(function(revert) {\r\n          revert();\r\n        });\r\n      });\r\n\r\n      return rewiredModule;\r\n    };\r\n\r\n    module.exports = rewireModule;\r\n\r\nSpec used:\r\n\r\n    /**\r\n      @see http://substantial.com/blog/2014/11/11/test-driven-react-how-to-manually-mock-components/\r\n    */\r\n    var React = require(\"react/addons\");\r\n    var TestUtils = React.addons.TestUtils;\r\n    var rewire = require(\"rewire\");\r\n    var rewireModule = require(\"../../rewire-module.js\");\r\n\r\n    describe('MainComponent', function() {\r\n      var component;\r\n\r\n      // `rewire` instead of `require`\r\n      var MainComponent = rewire(\"../components/MainComponent.react.js\");\r\n\r\n      // Replace the required module with a stub component.\r\n      rewireModule(MainComponent, {\r\n        ComponentA: React.createClass({\r\n          render: function() { return <div />; }\r\n        }),\r\n        ComponentB: React.createClass({\r\n          render: function() { return <div />; }\r\n        }),\r\n        ComponentC: React.createClass({\r\n          render: function() { return <div />; }\r\n        }),\r\n        ComponentD: React.createClass({\r\n          render: function() { return <div />; }\r\n        })\r\n      });\r\n\r\n      // Render the component from the rewired module.\r\n      beforeEach(function() {\r\n        component = TestUtils.renderIntoDocument( <MainComponent /> );\r\n      });\r\n\r\n      it(\"renders\", function() {\r\n        var foundComponent = TestUtils.findRenderedDOMComponentWithClass(\r\n          component, 'MainComponent');\r\n\r\n        expect(foundComponent).toBeDefined();\r\n      });\r\n    });\r\n\r\nUsing these node modules:\r\n\r\n    \"bootstrap\": \"^3.3.2\",\r\n    \"browserify\": \"^8.1.3\",\r\n    \"coffee-script\": \"^1.9.1\",\r\n    \"flux\": \"^2.0.1\",\r\n    \"gulp\": \"^3.8.11\",\r\n    \"gulp-bump\": \"^0.3.0\",\r\n    \"gulp-clean\": \"0.3.1\",\r\n    \"gulp-jasmine\": \"^2.0.0\",\r\n    \"gulp-jsdoc\": \"^0.1.4\",\r\n    \"gulp-jshint\": \"^1.9.2\",\r\n    \"gulp-less\": \"^3.0.0\",\r\n    \"gulp-minify-css\": \"^1.0.0\",\r\n    \"gulp-print\": \"1.1.0\",\r\n    \"gulp-react\": \"^3.0.1\",\r\n    \"gulp-rename\": \"1.2.0\",\r\n    \"gulp-sourcemaps\": \"^1.3.0\",\r\n    \"gulp-tap\": \"^0.1.3\",\r\n    \"gulp-uglify\": \"^1.1.0\",\r\n    \"gulp-util\": \"^3.0.3\",\r\n    \"gulp-verb\": \"^0.3.0\",\r\n    \"hammerjs\": \"^2.0.4\",\r\n    \"instafeed.js\": \"git+https://github.com/gunnarbergem/instafeed.js.git\",\r\n    \"jQuery.mmenu\": \"git+https://github.com/ganchenkor/jQuery.mmenu.git\",\r\n    \"jasmine-core\": \"^2.2.0\",\r\n    \"jquery\": \"^2.1.3\",\r\n    \"jquery-ui\": \"^1.10.5\",\r\n    \"jquery-ui-touch-punch\": \"^0.2.3\",\r\n    \"jsdoc-to-markdown\": \"^0.6.4\",\r\n    \"jshint-stylish\": \"^1.0.1\",\r\n    \"karma\": \"^0.12.31\",\r\n    \"karma-browserify\": \"^4.0.0\",\r\n    \"karma-chrome-launcher\": \"^0.1.7\",\r\n    \"karma-jasmine\": \"^0.3.5\",\r\n    \"karma-phantomjs-launcher\": \"^0.1.4\",\r\n    \"lodash\": \"^3.1.0\",\r\n    \"moment\": \"^2.9.0\",\r\n    \"object-assign\": \"^2.0.0\",\r\n    \"react\": \"^0.12.2\",\r\n    \"react-hammerjs\": \"^0.1.3\",\r\n    \"react-mini-router\": \"^1.0.0\",\r\n    \"react-tools\": \"^0.12.2\",\r\n    \"reactify\": \"^1.0.0\",\r\n    \"remarkable\": \"^1.6.0\",\r\n    \"rewire\": \"^2.3.1\",\r\n    \"underscore\": \"^1.7.0\",\r\n    \"vinyl-buffer\": \"^1.0.0\",\r\n    \"vinyl-source-stream\": \"^1.0.0\",\r\n    \"watchify\": \"^2.3.0\"\r\n\r\nNodeJS v0.12.0"},"comment":{"url":"https://api.github.com/repos/jhnns/rewire/issues/comments/85503013","html_url":"https://github.com/jhnns/rewire/issues/48#issuecomment-85503013","issue_url":"https://api.github.com/repos/jhnns/rewire/issues/48","id":85503013,"user":{"login":"jhnns","id":781746,"avatar_url":"https://avatars.githubusercontent.com/u/781746?v=3","gravatar_id":"","url":"https://api.github.com/users/jhnns","html_url":"https://github.com/jhnns","followers_url":"https://api.github.com/users/jhnns/followers","following_url":"https://api.github.com/users/jhnns/following{/other_user}","gists_url":"https://api.github.com/users/jhnns/gists{/gist_id}","starred_url":"https://api.github.com/users/jhnns/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jhnns/subscriptions","organizations_url":"https://api.github.com/users/jhnns/orgs","repos_url":"https://api.github.com/users/jhnns/repos","events_url":"https://api.github.com/users/jhnns/events{/privacy}","received_events_url":"https://api.github.com/users/jhnns/received_events","type":"User","site_admin":false},"created_at":"2015-03-24T13:49:55Z","updated_at":"2015-03-24T13:49:55Z","body":"Unfortunately there is no simple workaround because it's not a bug. rewire() is interfering with the require() mechanism which must be emulated when using browserify. I've [pointed out the required steps](https://github.com/jhnns/rewire/issues/13#issuecomment-40581072)."}}