-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f647b71
commit 6b8967e
Showing
7 changed files
with
132 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
const expect = require('chai').expect; | ||
const {Dic, DicConfigLoader} = require('./index'); | ||
|
||
class Service1 { | ||
constructor(service1Opts) { | ||
this.options = service1Opts; | ||
} | ||
} | ||
|
||
describe('DicConfigLoader', () => { | ||
before(function() { | ||
this.expect = { | ||
instanceof: async (dic, ins, classDef) => { | ||
expect(dic.get(ins)).instanceof(classDef); | ||
expect(await dic.getAsync(ins)).instanceof(classDef); | ||
} | ||
} | ||
}); | ||
|
||
beforeEach(function() { | ||
this.dic = new Dic(); | ||
this.dicConfigLoader = new DicConfigLoader(); | ||
}); | ||
|
||
describe('.loadConfig()', () => { | ||
describe('opts: aliases, options', () => { | ||
it('works', async function() { | ||
const {dic, dicConfigLoader} = this; | ||
|
||
dic.class('service1', Service1); | ||
|
||
dicConfigLoader.loadConfig(dic, { | ||
options: { | ||
service1: {} | ||
}, | ||
aliases: { | ||
service2: 'service1' | ||
} | ||
}); | ||
|
||
await this.expect.instanceof(dic, 'service1', Service1); | ||
await this.expect.instanceof(dic, 'service2', Service1); | ||
}); | ||
}); | ||
|
||
describe('opts: binding, imports', () => { | ||
it('works', async function() { | ||
const {dic, dicConfigLoader} = this; | ||
|
||
const package1Dic = new Dic(); | ||
dic.bind(package1Dic, { | ||
name: 'package1' | ||
}); | ||
|
||
dic.class('service1', Service1); | ||
|
||
dicConfigLoader.loadConfig(dic, { | ||
options: { | ||
service1: {} | ||
}, | ||
aliases: { | ||
service2: 'service1' | ||
}, | ||
bindings: { | ||
package1: { | ||
imports: { | ||
service1: 'service2' | ||
} | ||
} | ||
} | ||
}); | ||
|
||
await this.expect.instanceof(dic, 'service1', Service1); | ||
await this.expect.instanceof(dic, 'service2', Service1); | ||
await this.expect.instanceof(package1Dic, 'service1', Service1); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters