jhnns / rewire-webpack

Dependency injection for webpack bundles
The Unlicense
121 stars 20 forks source link

`__get__` returns "Cannot read property 'X' of undefined" #7

Closed mars closed 10 years ago

mars commented 10 years ago

Using Rewire-webpack v0.2.0 with Webpack 1.4.12 on Chrome 38:

    var React = require("react/addons");
    var TestUtils = React.addons.TestUtils;
    var rewire = require("rewire");

    var TestComponent = require("../test-component");

    describe('TestComponent', function() {
      var component;
      var ReactRouter = rewire("react-router");

      beforeEach(function() {
        this.original = {
          Link: ReactRouter.__get__("Link")
        };
        …

Throws Uncaught TypeError: Cannot read property 'Link' of undefined.

mars commented 10 years ago

Just noticed the release! Upgraded to Rewire-webpack v1.0.0 and still receive this error:

screen shot 2014-11-04 at 10 36 59

mars commented 10 years ago

This is not a bug after all; this was my own misunderstanding of how Rewire works.

I was trying to __get__() a property on the rewired module, but __get__() only retrieves local variables.

jhnns commented 10 years ago

:+1: