Refactor DI for simplicity and type safety
This commit improves the dependency injection mechanism by introducing a custom `injectKey` function. Key improvements are: - Enforced type consistency during dependency registration and instantiation. - Simplified injection process, abstracting away the complexity with a uniform API, regardless of the dependency's lifetime. - Eliminated the possibility of `undefined` returns during dependency injection, promoting fail-fast behavior. - Removed the necessity for type casting to `symbol` for injection keys in unit tests by using existing types. - Consalidated imports, combining keys and injection functions in one `import` statement.
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
import { expect } from 'vitest';
|
||||
|
||||
export async function expectThrowsAsync(
|
||||
method: () => Promise<unknown>,
|
||||
errorMessage: string,
|
||||
) {
|
||||
let error: Error | undefined;
|
||||
try {
|
||||
await method();
|
||||
} catch (err) {
|
||||
error = err;
|
||||
}
|
||||
expect(error).toBeDefined();
|
||||
expect(error).to.be.an(Error.name);
|
||||
if (errorMessage) {
|
||||
expect(error.message).to.equal(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
export async function expectDoesNotThrowAsync(
|
||||
method: () => Promise<unknown>,
|
||||
) {
|
||||
let error: Error | undefined;
|
||||
try {
|
||||
await method();
|
||||
} catch (err) {
|
||||
error = err;
|
||||
}
|
||||
expect(error).toBeUndefined();
|
||||
}
|
||||
Reference in New Issue
Block a user