tedi
Version:
Express wrappper written in typescript with dependency injection capabilities
58 lines (57 loc) • 2.61 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
const inversify = require("inversify");
describe("inversify", () => {
describe("child kernel", () => {
let weaponIdentifier = "Weapon";
let Katana = class Katana {
};
Katana = __decorate([
inversify.injectable()
], Katana);
let Shuriken = class Shuriken {
};
Shuriken = __decorate([
inversify.injectable()
], Shuriken);
let parentKernel;
let childKernel;
beforeEach(() => {
parentKernel = new inversify.Container();
parentKernel.bind(weaponIdentifier).to(Katana);
childKernel = new inversify.Container();
childKernel.parent = parentKernel;
});
it("should find the dependency", () => {
expect(childKernel.get(weaponIdentifier)).toEqual(jasmine.any(Katana));
});
it("weaponIdentifier should be bound", () => {
expect(childKernel.isBound(weaponIdentifier)).toBeTruthy();
});
describe("when we bind another class with the same identifier to the parentKernel", () => {
beforeEach(() => {
parentKernel.bind(weaponIdentifier).to(Shuriken);
});
it("an error should be throwned", () => {
expect(() => parentKernel.get(weaponIdentifier)).toThrow();
});
});
describe("when we bind a class with the same identifier to the child Kernel", () => {
beforeEach(() => {
childKernel.bind(weaponIdentifier).to(Shuriken);
});
it("childKernel should get the newly bound class", () => {
expect(childKernel.get(weaponIdentifier)).toEqual(jasmine.any(Shuriken));
});
it("parentKernel should have it's own class", () => {
expect(parentKernel.get(weaponIdentifier)).toEqual(jasmine.any(Katana));
});
});
});
});