Skip to content

Commit

Permalink
Merge pull request jestjs#1 from jamedranoa/bug/mocking-babel6
Browse files Browse the repository at this point in the history
add special slot '__esModule'
  • Loading branch information
jamedranoa committed Jan 22, 2016
2 parents b9b4bb0 + f70e60e commit 4456d43
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/lib/__tests__/moduleMocker-test.js
Expand Up @@ -75,6 +75,21 @@ describe('moduleMocker', function() {
expect(fooMock.nonEnumGetter).toBeUndefined();
});

it('does not mock __esModule special property (babel6)', function () {
var ClassFoo = function() {};

var fooModule = {
__esModule: true,
default: ClassFoo
};

var fooModuleMock = moduleMocker.generateFromMetadata(
moduleMocker.getMetadata(fooModule)
);

expect(fooModuleMock.__esModule).toEqual(fooModule.__esModule);
});

it('mocks ES2015 non-enumerable methods', function() {
class ClassFoo {
foo() {}
Expand Down
13 changes: 13 additions & 0 deletions src/lib/moduleMocker.js
Expand Up @@ -287,6 +287,12 @@ function generateMock(metadata, callbacks, refs) {

getSlots(metadata.members).forEach(slot => {
const slotMetadata = metadata.members[slot];
// special slot used by babel 6
if (slot === '__esModule') {
mock[slot] = slotMetadata;
return;
}

if (slotMetadata.ref != null) {
callbacks.push(() => mock[slot] = refs[slotMetadata.ref]);
} else {
Expand Down Expand Up @@ -349,6 +355,13 @@ function getMetadata(component, _refs) {
if (type !== 'array') {
if (type !== 'undefined') {
getSlots(component).forEach(slot => {
// special slot used by babel 6
if (slot === '__esModule') {
members = members || {};
members[slot] = component[slot];
return;
}

if (
slot.charAt(0) === '_' ||
(
Expand Down

0 comments on commit 4456d43

Please sign in to comment.