A babel plugin adding the ability to rewire modul dependency. This enables to mock modules for testing purposes.
I am trying to get babel-plugin-rewire@1.0.0-rc-2 to work on a babel 6 karma mocha webpack setup, and I have followed the instructions in the readme, and I am ending up with the following error
Uncaught TypeError: Cannot read property 'Rewire' of undefined
Any advice/assistance would be most appreciated
Uncaught TypeError: Cannot read property '__Rewire__' of undefined
//entry.js
import thingToRewire from './thing'
//thing.js
export default thing () {
require('./stuff')
}
e.g.
MyComponent.jsx has import someCoolFunctionThatShouldBeMocked
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR LOG: 'named exports are not supported in *.vue files.'
however, I do not see any __RewireAPI__
being added to exports in my test files :(
How can I spy on a function that is references from an object? Example:
a.js
const map = {
a,
b,
c
};
function run(options) {
map[options.val]();
}
function a() {...}
function b() {...}
function c() {...}
a.spec.js
import { a, __RewireAPI__ as ARewireAPI } from './a';
describe('a', () => {
describe('run', () => {
const spy= jasmine.createSpy('spy').and.callFake(() => {
...
});
beforeEach(() => {
ARewireAPI.__Rewire__('b', spy);
});
afterEach(() => {
TooltipRewireAPI.__ResetDependency__('b');
});
it('calls b()', () => {
a.run({val: 'b'}); // doesn't call the spy because what actually being called is the reference from the map object
});
});
});
TypeError: 'undefined' is not a function (evaluating '_get__('AGGrid').__ResetDependency__('AgGridReact')')
at :322