Skip to content

Commit

Permalink
Fix failing registry tests
Browse files Browse the repository at this point in the history
registry:
- Add clearRegistry to remove all container registrations
- Change internal list of containerRegistrations to a Map

registry.spec:
- Add teardown after each test to clear the registry so side effects of registrations from other tests can not impact subsequent tests

Fixes #146
  • Loading branch information
bingenito committed Apr 17, 2018
1 parent 7d0205b commit 53141c5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
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

0 comments on commit 53141c5

Please sign in to comment.