generated from Soontao/ts-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
required inject
Theo Sun edited this page Nov 9, 2020
·
2 revisions
use
@required
decorator to indicate framework MUST inject some values.
it('should throw error when can not provide value for @required value', async () => {
const ic = InjectContainer.New();
class A {
@required
@inject("v")
aV: string;
}
class B {
constructor(@required @inject("v") bV?) { }
}
class C {
run(@required @inject("v") cV: any) {
return cV;
}
}
class D {
static run(@required @inject("v") dV: any) { }
}
expect(() => ic.getInstance(A)).rejects.toThrow(RequiredNotFoundError);
expect(() => ic.getInstance(B)).rejects.toThrow(RequiredNotFoundError);
expect(async () => { const c = await ic.getWrappedInstance(C); return c.run(); }).rejects.toThrow(RequiredNotFoundError);
expect(async () => { const d = await ic.wrap(D); return d.run(); }).rejects.toThrow(RequiredNotFoundError);
});