From c32e79488f12100800dc02bf255e24a6b6603863 Mon Sep 17 00:00:00 2001 From: jacob Date: Sun, 28 Jan 2024 16:01:18 -0600 Subject: [PATCH] add test for init functionality --- test/core/ioc.test.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/core/ioc.test.ts b/test/core/ioc.test.ts index 48f4d8ad..de8015c1 100644 --- a/test/core/ioc.test.ts +++ b/test/core/ioc.test.ts @@ -1,12 +1,13 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'; import { CoreContainer } from '../../src/core/ioc/container'; import { EventEmitter } from 'events'; -import { DefaultLogging, Disposable, Init, Logging } from '../../src/core'; +import { DefaultLogging, Disposable, Emitter, Init, Logging } from '../../src/core'; import { CoreDependencies } from '../../src/types/ioc'; describe('ioc container', () => { let container: CoreContainer<{}> = new CoreContainer(); let dependency: Logging & Init & Disposable; + let dependency2: Emitter beforeEach(() => { dependency = { init: vi.fn(), @@ -16,6 +17,11 @@ describe('ioc container', () => { debug(): void {}, dispose: vi.fn() }; + dependency2 = { + addListener: vi.fn(), + removeListener: vi.fn(), + emit: vi.fn() + }; container = new CoreContainer(); }); const wait = (seconds: number) => new Promise((resolve) => setTimeout(resolve, seconds)); @@ -83,4 +89,13 @@ describe('ioc container', () => { container.ready(); expect(dependency.init).toHaveBeenCalledTimes(0); }); + + it('should init dependency depending on something else', () => { + container.add({ '@sern/client': dependency2 }); + container.upsert((cntr) => ({ + '@sern/logger': dependency + })); + container.ready(); + expect(dependency.init).toHaveBeenCalledTimes(1); + }) });