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

Fix failing registry tests #147

Merged
merged 1 commit into from
Apr 19, 2018
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
8 changes: 7 additions & 1 deletion src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ export class ContainerRegistration {
create: (options?: any) => Container;
}

const registeredContainers: { [id: string]: ContainerRegistration } = {};
const registeredContainers: Map<string, ContainerRegistration> = new Map();

/** Clears all container registrations. */
export function clearRegistry() {
registeredContainers.clear();
container = undefined;
}

/** Register a container type in the registry.
* @param {string} id Unique identifier of the container type (eg. Electron).
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/registry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ class TestContainer extends DefaultContainer {

describe("registry", () => {
describe("resolveContainer", () => {
let container: Container = registry.resolveContainer();
afterEach(() => {
registry.clearRegistry();
});

it("No matching condition resolves default", () => {
let container: Container = registry.resolveContainer();
expect(container).toBeDefined();
expect(container.hostType).toEqual("Default");
});

it("Subsequent call returns from cache", () => {
let container: Container = registry.resolveContainer();
let container2: Container = registry.resolveContainer();
expect(container2).toBeDefined();
expect(container2).toEqual(container);
Expand Down