Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot rewire within IIFE #57

Closed
masimplo opened this issue Apr 23, 2015 · 1 comment
Closed

Cannot rewire within IIFE #57

masimplo opened this issue Apr 23, 2015 · 1 comment
Labels

Comments

@masimplo
Copy link

My source looks like:

(function (sut) {
    'use strict';
    var testVar = 'Hello from original';

    sut.testMe = function(){
         return testvar;
    }
}(module.exports));

trying to test this gives me a failure:

(function () {
    'use strict';
    var rewire = require("rewire");
    var sut = rewire('../../lib/sut');
    sut.__set__('testVar', 'hello from mock');

    describe('Rewire', function(){
         it('fails', function(){
              expect(sut.testMe()).to.equal('Hello from mock');
         })
    }
)

The mock is not respected and the source has the original value for the testVar.
But if I remove my src from the IIFE then everything works. Am I doing something wrong?

@jhnns
Copy link
Owner

jhnns commented Apr 27, 2015

Nope, that is actually a limitation by JavaScript. It is not possible to access a function's scope...

jhnns added a commit that referenced this issue Apr 27, 2015
@jhnns jhnns added the wontfix label Apr 27, 2015
@jhnns jhnns closed this as completed Apr 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants