First check-in of the code from the Obsidian Prj project.

This commit is contained in:
2024-08-14 19:40:52 +02:00
parent 1341427590
commit 6c4db19926
14 changed files with 495 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
import { test_IDIContainer } from './IDIContainer.spec';
import { DIContainer } from '../DIContainer';
test_IDIContainer(DIContainer);

View File

@@ -0,0 +1,35 @@
import { ITSInjex_, ITSInjex } from '../interfaces/IDIContainer';
/**
* Test the implementation of a DIContainer
* @param Container The DIContainer implementation to test.
* Must implement {@link ITSInjex}, {@link ITSInjex_}
*/
export function test_IDIContainer(Container: ITSInjex_): void {
describe('IDIContainer Implementation Tests', () => {
let container: ITSInjex;
beforeEach(() => {
container = Container.getInstance();
});
it('should register and resolve a dependency', () => {
const identifier = 'myDependency';
const dependency = { value: 42 };
container.register(identifier, dependency);
const resolvedDependency =
container.resolve<typeof dependency>(identifier);
expect(resolvedDependency).toBe(dependency);
});
it('should throw an error when resolving a non-registered dependency', () => {
const identifier = 'nonExistentDependency';
expect(() => container.resolve<unknown>(identifier)).toThrow();
});
// Add more tests as necessary
});
}