Skip to content

### Enhance Unit Tests with Mocks and Dependency Injection Updates#62

Merged
ColinMichaels merged 1 commit into
devfrom
fixes/refactoring
Feb 28, 2026
Merged

### Enhance Unit Tests with Mocks and Dependency Injection Updates#62
ColinMichaels merged 1 commit into
devfrom
fixes/refactoring

Conversation

@ColinMichaels
Copy link
Copy Markdown
Owner

  • Added testing utilities to multiple component and service tests:
    • Integrated provideHttpClient and provideHttpClientTesting in weather, dock, and finder-app component tests to enable HTTP testing capabilities.
    • Added RouterTestingModule to projects-overview.component.spec for router-related tests.
    • Mocked dependencies with Jasmine spies in unit tests for auth.service, home-terminal-window.component, and cli-game.component.
  • Refactored auth.service to gracefully handle the absence of Firebase services by making Auth injection optional and introducing fallback behaviors.
  • Wrapped Firebase Firestore and Storage calls in helper methods within firestore.service to improve testability and maintain runtime behavior consistency.
  • Enhanced firestore.service to handle optional Firestore injection and replaced direct Firestore method calls with wrapper functions, enabling streamlined mocking for tests.
  • Made realtime-db.service initialization conditional to allow null-safe usage.

These changes improve test reliability, maintainability, and resilience, enabling easier mocking and dependency injection for unit testing.

- Added testing utilities to multiple component and service tests:
  - Integrated `provideHttpClient` and `provideHttpClientTesting` in `weather`, `dock`, and `finder-app` component tests to enable HTTP testing capabilities.
  - Added `RouterTestingModule` to `projects-overview.component.spec` for router-related tests.
  - Mocked dependencies with Jasmine spies in unit tests for `auth.service`, `home-terminal-window.component`, and `cli-game.component`.
- Refactored `auth.service` to gracefully handle the absence of Firebase services by making `Auth` injection optional and introducing fallback behaviors.
- Wrapped Firebase Firestore and Storage calls in helper methods within `firestore.service` to improve testability and maintain runtime behavior consistency.
- Enhanced `firestore.service` to handle optional Firestore injection and replaced direct Firestore method calls with wrapper functions, enabling streamlined mocking for tests.
- Made `realtime-db.service` initialization conditional to allow null-safe usage.

These changes improve test reliability, maintainability, and resilience, enabling easier mocking and dependency injection for unit testing.

Signed-off-by: Colin Michaels <colin@colinmichaels.com>
@ColinMichaels ColinMichaels self-assigned this Feb 28, 2026
@ColinMichaels ColinMichaels merged commit ff97939 into dev Feb 28, 2026
1 check failed
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant