Skip to content

Commit f9975dc

Browse files
authored
Merge pull request #34 from xxxtonixxx/fix/edge-cases
fix(Container): Added comprobation to edge cases
2 parents 96d898d + b4b2ce9 commit f9975dc

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/Container.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class Container {
7070
let service = this.findService(identifier);
7171

7272
// find if instance of this object already initialized in the container and return it if it is
73-
if (service && service.instance)
73+
if (service && service.instance !== null && service.instance !== undefined)
7474
return service.instance as T;
7575

7676
// if named service was requested and its instance was not found plus there is not type to know what to initialize,

test/Container.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,34 @@ describe("Container", function() {
99

1010
beforeEach(() => Container.reset());
1111

12+
describe("get", () => {
13+
14+
it("should be able to get a boolean", () => {
15+
const booleanTrue = "boolean.true";
16+
const booleanFalse = "boolean.false";
17+
Container.set(booleanTrue, true);
18+
Container.set(booleanFalse, false);
19+
20+
Container.get(booleanTrue).should.be.true;
21+
Container.get(booleanFalse).should.be.false;
22+
});
23+
24+
it("should be able to get an empty string", () => {
25+
const emptyString = "emptyString";
26+
Container.set(emptyString, "");
27+
28+
Container.get(emptyString).should.be.eq("");
29+
});
30+
31+
it("should be able to get the 0 number", () => {
32+
const zero = "zero";
33+
Container.set(zero, 0);
34+
35+
Container.get(zero).should.be.eq(0);
36+
});
37+
38+
});
39+
1240
describe("set", function() {
1341

1442
it("should be able to set a class into the container", function() {

0 commit comments

Comments
 (0)