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

__Rewire__ interferes with Jasmine's this #193

Open
0nse opened this issue Jun 13, 2017 · 0 comments
Open

__Rewire__ interferes with Jasmine's this #193

0nse opened this issue Jun 13, 2017 · 0 comments

Comments

@0nse
Copy link

0nse commented Jun 13, 2017

Hi all,

I'm trying to use Rewire together with Karma and Jasmine. Generally, it works well. However, as soon as I call __Rewire__, Jasmine's this becomes undefined.
I use

"babel-plugin-rewire": "^1.1.0"

and import it as follows:

import { __Rewire__ as rewireAPI } from '../some-module';

When I'm assigning to this it works:

describe('Working test', () => {
      beforeEach(() => {
          this.variable = 'a value';
      });
      it('should be able to read the variable bound to userContext', () => {
          expect(this.variable).not.toBe(undefined);
          expect(this.variable).toBe('a value');
      });
});

However, if I rewire as follows:

describe('Failing test', () => {
    beforeEach(() => {
        this.variable = 'a value';
        rewireAPI.__Rewire__('functionToRewire', () => {});
    });
    it('should be able to read the variable bound to userContext', () => {
        expect(this.variable).not.toBe(undefined);
        expect(this.variable).toBe('a value');
    });

});

I get the following error:
TypeError: undefined is not a function (evaluating '_get__('rewireAPI').__Rewire__('functionToRewire', function () {})')

I have seen #109 but I believe this issue is different as I can use Rewire perfectly fine as long as I refrain from using this.

You can find a minimal example here. The error is unrelated to Mocha, which I have just included for increasing readability of the test results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant