Skip to content

Commit 647cfd5

Browse files
committed
test: add test for instance scope
1 parent 998c8a7 commit 647cfd5

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/constant.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export const CLASS_CONSTRUCTOR_TAG = `${PREFIX}::CLASS_CONSTRUCTOR_TAG`;
88

99
export const ScopeType = {
1010
SINGLETON: `${PREFIX}::SINGLETON`,
11-
EXECUTION: `${PREFIX}::EXECUTION`,
1211
TRANSIENT: `${PREFIX}::TRANSIENT`,
1312
} as const;
1413

test/container.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { strict as assert } from "assert";
22
import { Container, createCustomError, ErrorType } from "../src";
33
import { UnInjectable, Foo, Bar } from "./fixtures/items/container";
4-
import { Config, Config2 } from "./fixtures/items/config";
4+
import { Config, Config2, TransientConfig } from "./fixtures/items/config";
55

66

77
describe("container.test.js", () => {
@@ -88,4 +88,20 @@ describe("container.test.js", () => {
8888
assert(error.message.includes("class BB::aa => class Object"));
8989
});
9090
});
91+
92+
describe("instance scope", () => {
93+
const container = new Container();
94+
container.set(Config);
95+
container.set(TransientConfig);
96+
97+
it("single scope should be ok", () => {
98+
const config = container.get(Config);
99+
assert(container.get(Config) === config);
100+
});
101+
102+
it("transient scope should be ok", () => {
103+
const config = container.get(TransientConfig);
104+
assert(container.get(TransientConfig) !== config);
105+
});
106+
});
91107
});

test/fixtures/items/config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable } from "../../../src";
1+
import { Injectable, ScopeType } from "../../../src";
22

33
@Injectable()
44
export class Config {
@@ -42,4 +42,7 @@ export class Config2 {
4242
get key() {
4343
return this.#key;
4444
}
45-
}
45+
}
46+
47+
@Injectable({ scope: ScopeType.TRANSIENT })
48+
export class TransientConfig { }

0 commit comments

Comments
 (0)