Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ContainerModule load to support sync load functions #284

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading