diff --git a/lib/injector.js b/lib/injector.js index 667171b..0e6c116 100644 --- a/lib/injector.js +++ b/lib/injector.js @@ -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]; } diff --git a/test/injector.spec.js b/test/injector.spec.js index af99e40..ad76e7d 100644 --- a/test/injector.spec.js +++ b/test/injector.spec.js @@ -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([