Skip to content

Commit

Permalink
fix: a scope should not get instances from parent scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
lbguilherme committed Jan 21, 2021
1 parent 85fa7d7 commit 3ad871f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions spec/inject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ describe("env", () => {
setupScope(() => {
const instance3 = use(TestService);

expect(instance1).toBe(instance3);
expect(instance3).not.toBe(instance1);
});
});

setupScope(() => {
expect(constructorCalledTimes).toBe(1);
expect(constructorCalledTimes).toBe(2);

setupScope(() => {
use(TestService);

expect(constructorCalledTimes).toBe(2);
expect(constructorCalledTimes).toBe(3);
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/scope-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ export class ScopeContext {
private readonly values = new Map<string, unknown>();

getServiceInstance(name: string): unknown {
return this.serviceInstances.has(name) ? this.serviceInstances.get(name) : this.parent?.getServiceInstance(name);
return this.serviceInstances.get(name);
}

hasServiceInstance(name: string): boolean {
return this.serviceInstances.has(name) || (this.parent?.hasServiceInstance(name) ?? false);
return this.serviceInstances.has(name);
}

setServiceInstance(name: string, value: unknown) {
Expand Down

0 comments on commit 3ad871f

Please sign in to comment.