##// END OF EJS Templates
minor fixes
minor fixes

File last commit:

r44:7a410676c874 di-typescript
r45:3c6524f04866 di-typescript
Show More
ContainerTests.ts
93 lines | 2.6 KiB | video/mp2t | TypeScriptLexer
/ test / ts / ContainerTests.ts
cin
tests
r41 import { test, TapeWriter } from "./TestTraits";
cin
tests, refactoring, fixes
r40 import { Container } from "@implab/core/di/Container";
import { ReferenceDescriptor } from "@implab/core/di/ReferenceDescriptor";
import { AggregateDescriptor } from "@implab/core/di/AggregateDescriptor";
cin
tests
r41 import { ValueDescriptor } from "@implab/core/di/ValueDescriptor";
import { TraceSource, DebugLevel } from "@implab/core/log/TraceSource";
import { Foo } from "./mock/Foo";
import { Bar } from "./mock/Bar";
import { isNull } from "@implab/core/safe";
cin
tests, refactoring, fixes
r40
cin
tests
r41 test("Container register/resolve tests", async t => {
cin
tests, refactoring, fixes
r40 const container = new Container();
const connection1 = "db://localhost";
cin
Container.configure sync/async tests
r42 t.throws(
() => container.register("bla-bla", "bla-bla"),
"Do not allow to register anything other than descriptors"
);
cin
tests, refactoring, fixes
r40
cin
Container.configure sync/async tests
r42 t.doesNotThrow(
() => container.register("connection", new ValueDescriptor(connection1)),
"register ValueDescriptor"
);
cin
tests, refactoring, fixes
r40
cin
fixes, tests...
r44 t.equals(container.resolve("connection"), connection1, "resolve string value");
cin
Container.configure sync/async tests
r42
t.doesNotThrow(
() => container.register(
"dbParams",
new AggregateDescriptor({
timeout: 10,
connection: new ReferenceDescriptor({ name: "connection" })
})
),
"register AggregateDescriptor"
cin
tests, refactoring, fixes
r40 );
cin
fixes, tests...
r44 const dbParams = container.resolve("dbParams");
cin
Container.configure sync/async tests
r42 t.equals(dbParams.connection, connection1, "should get string value 'dbParams.connection'");
cin
tests
r41 });
test("Container configure/resolve tests", async t => {
const container = new Container();
await container.configure({
foo: {
$type: Foo
},
cin
tests, refactoring, fixes
r40
cin
Container.configure sync/async tests
r42 box: {
$type: Bar,
params: {
$dependency: "foo"
}
},
cin
tests
r41 bar: {
$type: Bar,
params: {
db: {
provider: {
$dependency: "db"
}
}
}
}
});
cin
Container.configure sync/async tests
r42 t.pass("should configure from js object");
cin
tests
r41
const f1 = container.resolve("foo");
cin
Container.configure sync/async tests
r42
t.assert(!isNull(f1), "foo should be not null");
t.throws(() => container.resolve("bar"), "should not resolve dependency 'db'");
});
test("Load configuration from module", async t => {
const container = new Container();
await container.configure("test/mock/config1");
t.pass("The configuration should load");
const f1 = container.resolve("foo");
cin
tests
r41 t.assert(!isNull(f1), "foo should be not null");
const b1 = container.resolve("bar");
cin
Container.configure sync/async tests
r42 t.assert(!isNull(b1), "foo should be not null");
cin
tests, refactoring, fixes
r40 });