First check-in of the code from the Obsidian Prj project.
This commit is contained in:
4
src/__tests__/DIContainer.test.ts
Normal file
4
src/__tests__/DIContainer.test.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { test_IDIContainer } from './IDIContainer.spec';
|
||||
import { DIContainer } from '../DIContainer';
|
||||
|
||||
test_IDIContainer(DIContainer);
|
35
src/__tests__/IDIContainer.spec.ts
Normal file
35
src/__tests__/IDIContainer.spec.ts
Normal 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
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user