Skip to content

Commit

Permalink
Merge pull request #284 from inversify/feat/update-container-module-l…
Browse files Browse the repository at this point in the history
…oad-to-allow-returning-undefined

Update ContainerModule load to support sync load functions
  • Loading branch information
notaphplover authored Jan 11, 2025
2 parents 3d3983b + eb3cbd4 commit e65df4e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/slimy-otters-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@inversifyjs/container": minor
---

Updated `ContainerModule.load` to support sync load functions
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,23 @@ describe(ContainerModule.name, () => {

describe('.load', () => {
describe('when called', () => {
let optionsFixture: ContainerModuleLoadOptions;

let result: unknown;

beforeAll(() => {
result = new ContainerModule(loadMock).load;
beforeAll(async () => {
optionsFixture = Symbol() as unknown as ContainerModuleLoadOptions;

result = await new ContainerModule(loadMock).load(optionsFixture);
});

it('should call load()', () => {
expect(loadMock).toHaveBeenCalledTimes(1);
expect(loadMock).toHaveBeenCalledWith(optionsFixture);
});

it('should return expected value', () => {
expect(result).toBe(loadMock);
expect(result).toBeUndefined();
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ export interface ContainerModuleLoadOptions {

export class ContainerModule {
readonly #id: number;
readonly #load: (options: ContainerModuleLoadOptions) => Promise<void>;
readonly #load: (options: ContainerModuleLoadOptions) => void | Promise<void>;

constructor(load: (options: ContainerModuleLoadOptions) => Promise<void>) {
constructor(
load: (options: ContainerModuleLoadOptions) => void | Promise<void>,
) {
this.#id = getContainerModuleId();
this.#load = load;
}
Expand All @@ -35,7 +37,7 @@ export class ContainerModule {
return this.#id;
}

public get load(): (options: ContainerModuleLoadOptions) => Promise<void> {
return this.#load;
public async load(options: ContainerModuleLoadOptions): Promise<void> {
await this.#load(options);
}
}

0 comments on commit e65df4e

Please sign in to comment.