speedskater/babel-plugin-rewire

Error when executing Handling of default exports demo

Opened this issue · 0 comments

I am attempting to run the demo code for: Handling of default exports.

I am using babel with numerous plugins
"babel-cli": "^6.24.0",
"babel-core": "^6.9.1",
"babel-loader": "^6.2.4",
"babel-plugin-istanbul": "^4.1.1",
"babel-plugin-lodash": "^3.2.6",
"babel-plugin-resolver": "^1.1.0",
"babel-plugin-rewire": "^1.0.0",
"babel-plugin-transform-es3-member-expression-literals": "6.8.0",
"babel-plugin-transform-es3-property-literals": "6.8.0",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.23.0",
"babel-register": "^6.11.6",
"babelify": "~6.3.0",

foo.js

function message() {
   return 'Hello world';
}

export function foo() {
   return message();
}

foo-spec.js
import FooModule from './foo.js';
import { foo, RewireAPI as FooModuleRewireAPI } from './foo.js';
const chai = require('chai');
const expect = chai.expect();

describe('module default export test', function() {
   it('should demonstrate the default exported rewire api', function() {
      expect( foo() ).to.equal('Hello world');
      FooModule.__Rewire__('message', function() {
         return 'my message';
      });
      expect( foo() ).to.equal('my message');
      FooModule.__ResetDependency__('message');
   });
   
   it('should demonstrate the rewire apis named export', function() {
      expect( foo() ).to.equal('Hello world');
      FooModuleRewireAPI.__Rewire__('message', function() {
         return 'my message';
      });
      expect( foo() ).to.equal('my message');
      FooModuleRewireAPI.__ResetDependency__('message');
   });
});

The results are:

module default export test
  1) should demonstrate the default exported rewire api
  2) should demonstrate the rewire apis named export


0 passing (35ms)
2 failing

1) module default export test should demonstrate the default exported rewire api:
   TypeError: _get__(...) is not a function
    at Context.<anonymous> (specs/data-layer/unit/foo-spec.js:8:7)

2) module default export test should demonstrate the rewire apis named export:
   TypeError: _get__(...) is not a function
    at Context.<anonymous> (specs/data-layer/unit/foo-spec.js:17:7)

Please explain what it wrong.