Skip to content

Commit

Permalink
Added test case for #528 (#540)
Browse files Browse the repository at this point in the history
* Added test case for #528

* Added test case for #528
  • Loading branch information
remojansen authored Apr 24, 2017
1 parent 52596e0 commit 3553c79
Showing 1 changed file with 72 additions and 1 deletion.
73 changes: 72 additions & 1 deletion test/bugs/bugs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ describe("Bugs", () => {

});

it("Should be able inject into abstract base class without decorators", () => {
it("Should be able to inject into abstract base class without decorators", () => {

let TYPES = {
Warrior: "Warrior",
Expand Down Expand Up @@ -736,4 +736,75 @@ describe("Bugs", () => {
expect(samurai.primaryWeapon.name).to.eql("Katana");
});

it("Should be able to combine unmanaged and managed injections ", () => {

interface Model<T> {
instance: T;
}

interface RepoBaseInterface<T> {
model: Model<T>;
}

class Type {
public name: string;
public constructor() {
this.name = "Type";
}
}

@injectable()
class RepoBase<T> implements RepoBaseInterface<T> {

public model: Model<T>;

constructor(
// using @unmanaged() here is right
// because entityType is NOT Injected by inversify
@unmanaged() entityType: { new (): T; }
) {
this.model = { instance: new entityType() };
}

}

@injectable()
class TypedRepo extends RepoBase<Type> {
constructor() {
super(Type); // unmanaged injection (NOT Injected by inversify)
}
}

@injectable()
class BLBase<T> {

public repository: RepoBaseInterface<T>;

constructor(
// using @unmanaged() here would wrong
// because repository is injected by inversify
repository: RepoBaseInterface<T>
) {
this.repository = repository;
}
}

@injectable()
class TypedBL extends BLBase<Type> {
constructor(
repository: TypedRepo // Injected by inversify (no @inject required)
) {
super(repository); // managed injection (Injected by inversify)
}
}

const container = new Container();
container.bind<TypedRepo>(TypedRepo).toSelf();
container.bind<TypedBL>("TypedBL").to(TypedBL);

const typedBL = container.get<TypedBL>("TypedBL");
expect(typedBL.repository.model.instance.name).to.eq(new Type().name);

});

});

0 comments on commit 3553c79

Please sign in to comment.