Skip to content

Commit

Permalink
fix: correct private module initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
nikku committed Mar 3, 2022
1 parent 3f43764 commit 4ddac63
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export default function Injector(modules, parent) {

var clonedModule = Object.keys(moduleDefinition).reduce(function(clonedModule, key) {

if (key !== '__exports__' && key !== '__modules__') {
if (key !== '__exports__' && key !== '__modules__' && key !== '__init__' && key !== '__depends__') {
clonedModule[key] = moduleDefinition[key];
}

Expand Down
37 changes: 37 additions & 0 deletions test/injector.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,43 @@ describe('injector', function() {
});


it('should initialize', function() {

// given
const loaded = [];

// when
const injector = new Injector([
{
__exports__: [ 'foo' ],
__modules__: [
{
__init__: [ () => loaded.push('nested') ],
bar: [ 'value', 10 ]
}
],
__init__: [ (bar) => loaded.push('module' + bar) ],
'foo': [
'factory',
function(bar) {
return bar;
}
]
}
]);

// then
expect(loaded).to.eql([
'nested',
'module10'
]);

expect(function() {
injector.get('bar');
}).to.throw(/No provider for "bar"/);
});


it('should only create one private child injector', function() {

const injector = new Injector([
Expand Down

0 comments on commit 4ddac63

Please sign in to comment.