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

add special slot '__esModule' #690

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/lib/__tests__/moduleMocker-test.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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