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); + }) });