Skip to content

Commit

Permalink
Add test to ensure that we don't break "obj.require()" calls
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-tikhonov committed Mar 18, 2017
1 parent 659852f commit 0831925
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 3 deletions.
3 changes: 3 additions & 0 deletions __tests__/modules/a.js
Expand Up @@ -2,4 +2,7 @@ module.exports = {
a() {
return 'a - original';
},
require() {
return 'require method in a.js';
},
};
4 changes: 4 additions & 0 deletions __tests__/modules/amd.js
Expand Up @@ -10,5 +10,9 @@ define((require) => { // eslint-disable-line no-undef
getB() {
return b();
},

callRequireMethod() {
return a.require();
},
};
});
4 changes: 4 additions & 0 deletions __tests__/modules/commonjs.js
Expand Up @@ -9,4 +9,8 @@ module.exports = {
getB() {
return b();
},

callRequireMethod() {
return a.require();
},
};
8 changes: 6 additions & 2 deletions __tests__/modules/es6.js
@@ -1,10 +1,14 @@
import { a } from './a.js';
import a, { a as methodA } from './a.js';
import b from './b.js';

export function getA() {
return a();
return methodA();
}

export function getB() {
return b();
}

export function callRequireMethod() {
return a.require();
}
6 changes: 6 additions & 0 deletions __tests__/tests.js
Expand Up @@ -55,6 +55,12 @@ describe('injectify-loader', () => {

assert.throws(injectInvalidDependencies, /The following injections are invalid:\n- \.\/c\.js/);
});

it('does not break someObject.require calls', () => {
const module = injector.moduleInjector();

assert.equal(module.callRequireMethod(), 'require method in a.js');
});
});
});
});
2 changes: 1 addition & 1 deletion src/wrapper_template.js
Expand Up @@ -19,7 +19,7 @@ export default template(`
throw new Error('Some of the injections you passed in are invalid.\\n' +
'Valid injection targets for this module are:\\n' + validDependenciesString + '\\n' +
'The following injections were passed in:\\n' + injectedDependenciesString + '\\n' +
'The following injections are invalid:\\n' + invalidDependenciesString
'The following injections are invalid:\\n' + invalidDependenciesString + '\\n'
);
}
})();
Expand Down

0 comments on commit 0831925

Please sign in to comment.