-
Notifications
You must be signed in to change notification settings - Fork 719
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update service bindings to avoid caching
- Loading branch information
1 parent
64aa399
commit 42d927f
Showing
4 changed files
with
60 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { describe, it } from 'mocha'; | ||
import sinon from 'sinon'; | ||
|
||
import { Container, injectable, preDestroy } from '../../src/inversify'; | ||
|
||
describe('Issue 1416', () => { | ||
it('should allow providing default values on optional bindings', async () => { | ||
@injectable() | ||
class Test1 { | ||
public stub: sinon.SinonStub<unknown[], void> = sinon.stub(); | ||
|
||
@preDestroy() | ||
public destroy() { | ||
this.stub(); | ||
} | ||
} | ||
|
||
@injectable() | ||
class Test2 { | ||
public destroy(): void {} | ||
} | ||
|
||
@injectable() | ||
class Test3 { | ||
public destroy(): void {} | ||
} | ||
|
||
const container: Container = new Container({ defaultScope: 'Singleton' }); | ||
|
||
container.bind(Test1).toSelf(); | ||
container.bind(Test2).toService(Test1); | ||
container.bind(Test3).toService(Test1); | ||
|
||
const test1: Test1 = container.get(Test1); | ||
container.get(Test2); | ||
container.get(Test3); | ||
|
||
container.unbindAll(); | ||
|
||
sinon.assert.calledOnce(test1.stub); | ||
}); | ||
}); |
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