backend starter kit with rich features!
class Head {
constructor(eye, nose, mouth) {
this.eye = eye;
this.nose = nose;
this.mouth = mouth;
}
}
it("resolves autowired instance", () => {
const head = Container.resolve(Head);
expect(head.eye).toBeInstanceOf(Eye);
expect(head.nose).toBeInstanceOf(Nose);
expect(head.mouth).toBeInstanceOf(Mouth);
expect(head.mouth.teeth).toBeInstanceOf(Teeth);
});
No need to use decorator syntax or other.
Container
just inspect the class's constructor properties and inject them in its registry
.
Each is equivalent to an interface.
This uses vitest v1.6.0 as testing framework.
You don't need to import vitest APIs like describe
, it
, expect
.
Because I set up to use vitest APIs globally in vitest.config.ts
.
If you want to know how, see this vitest documentation.
This uses supertest v7.0.0 to test http server.