Skip to content

Commit fccb56f

Browse files
committed
Adds test case for singleton constructor that don't implement dispose method
1 parent 9db754c commit fccb56f

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
- [x] remove done call
2121
- [x] add experimental contribution phase into a revealing construction pattern
2222
- [x] refactor APIs to be more explicit
23-
- [ ] test case when singletons do NOT implement a dispose method (see test coverage)
23+
- [x] test case when singletons do NOT implement a dispose method (see test coverage)
2424
- [x] cleanup
2525
- [x] remove memoize if not used
2626
- [x] remove merge if not used

test/spec/dispose.spec.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('Given a container', function () {
5656
BAR_2.dispose.reset()
5757
})
5858

59-
it('should not release the instance if still in use', function () {
59+
it('should not dispose the instance if still in use', function () {
6060
var firstRequest = container.get('bar')
6161
var secondRequest = container.get('bar')
6262

@@ -69,6 +69,27 @@ describe('Given a container', function () {
6969
expect(container.get('bar')).to.equal(firstRequest)
7070
})
7171

72+
describe('and the instance does not have a dispose method', function () {
73+
74+
class Foo {}
75+
76+
beforeEach(function () {
77+
container = iniettore.create(function (context) {
78+
context
79+
.map('foo').to(Foo)
80+
.as(TRANSIENT, SINGLETON, CONSTRUCTOR)
81+
})
82+
container.get('foo')
83+
})
84+
85+
it('should not throw an Error', function () {
86+
function testCase() {
87+
container.release('foo')
88+
}
89+
expect(testCase).to.not.throw(TypeError)
90+
})
91+
})
92+
7293
describe('the same amount of times it has been acquired', function () {
7394

7495
it('should release the instance, call dispose() method', function () {
@@ -117,7 +138,7 @@ describe('Given a container', function () {
117138
})
118139
})
119140

120-
describe('when releasing a persistent singleton', function () {
141+
describe('when releasing a persistent singleton adn there is no more reference to the singleton', function () {
121142

122143
before(function () {
123144
container = iniettore.create(function (context) {
@@ -127,7 +148,7 @@ describe('Given a container', function () {
127148
})
128149
})
129150

130-
it('should have test coverage', function () {
151+
it('should not dispose the instance', function () {
131152
container.get('baz')
132153
container.release('baz')
133154
expect(BazDisposeSpy).to.not.be.called

0 commit comments

Comments
 (0)