The Alliance Research Indicators client uses Jest withDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/AllianceBioversityCIAT/alliance-research-indicators-client/llms.txt
Use this file to discover all available pages before exploring further.
jest-preset-angular for all unit tests. Spec files are co-located with the subject file, shared fixtures live in src/app/testing/, and a project-wide coverage floor is enforced by jest.config.ts on every CI run. This page explains the test setup, how to run tests, where fixtures come from, and what to test for each code category.
Test environment
Tests run in ajsdom environment using the jest-preset-angular preset, which bridges the Angular compilation pipeline (via ts-jest / Babel) with Jest’s test runner. The bootstrapping file at src/setup-jest.ts is loaded after the framework before every suite.
jest.config.ts
Path aliases in tests
All TypeScript path aliases declared intsconfig.json are mirrored in jest.config.ts under moduleNameMapper. Use the aliases — never use relative ../../.. imports in spec files.
| Alias | Resolves to |
|---|---|
@shared/* | src/app/shared/* |
@services/* | src/app/shared/services/* |
@interfaces/* | src/app/shared/interfaces/* |
@components/* | src/app/shared/components/* |
@pages/* | src/app/pages/* |
@guards/* | src/app/shared/guards/* |
@interceptors/* | src/app/shared/interceptors/* |
@envs/* | src/environments/* |
@utils/* | src/app/shared/utils/* |
identity-obj-proxy and the @microsoft/clarity SDK is mocked at tests/mocks/clarityMock.ts.
Running tests
All commands run from theresearch-indicators/ directory.
text, text-summary, cobertura, and lcov output. The lcov report is consumed by SonarCloud in the sonarcloud-analysis.yml CI workflow.
Coverage floors
The following project-wide thresholds are enforced byjest.config.ts. If any threshold is breached the test run exits with a non-zero code and CI fails.
jest.config.ts (coverage thresholds)
| Metric | Floor |
|---|---|
| Statements | 40% |
| Branches | 20% |
| Lines | 45% |
| Functions | 30% |
What is excluded from coverage
The following files are excluded from coverage measurement by design. Do not add new exclusions without a documented reason.jest.config.ts (coverage exclusions)
app.config.ts and app.routes.ts are framework bootstrap/configuration files with no testable logic. websocket.service.ts depends on a live socket connection. alert.component.ts is a thin display wrapper with no branching logic.
Coverage is collected from ./src/app/**/*.ts and ./src/app/**/*.html, excluding routing and module files.
Where spec files live
Co-locate*.spec.ts files next to the subject file. This keeps test files discoverable and prevents them from drifting when the subject file is moved.
alert.component.ts is excluded from the test run via testPathIgnorePatterns in jest.config.ts.
Shared fixtures in src/app/testing/
All shared mocks and test fixtures live in src/app/testing/mock-services.mock.ts. Always import from here — never re-mock the same service in individual spec files. Duplicating mocks creates drift and makes refactors painful.
The file exports pre-built mock objects for every major injectable:
src/app/testing/mock-services.mock.ts (excerpt)
MainResponse<T> shape:
What to test
Service tests
Services that delegate HTTP calls throughApiService must be tested with HttpTestingController. Always assert on the full MainResponse<T> envelope — the status, successfulRequest, and data fields — not just the inner data.
src/app/shared/services/example.service.spec.ts
ActionsService link-to-existing modal, not by silently retrying.
Component tests
Component specs must cover:- Role-conditional rendering — assert that elements visible to one role are absent for another. Use the
cacheServiceMockwith itsdataCachesignal to swap the simulated role. - Signal-driven state transitions — update a writable signal and assert the rendered DOM reflects the new value.
- Form validity — set invalid values on reactive form controls and assert that the submit button is disabled and error messages appear.
- Error surfaces — trigger an error path and assert that the appropriate toast or inline message is shown.
src/app/pages/example/example.component.spec.ts
Interceptor tests
For interceptors, verify:- Token attachment (
jWtInterceptor— assert theAuthorizationheader is set). - HTTP error surfacing (
httpErrorInterceptor— assert toast/alert dispatch viaActionsService). - 409 conflict flow — assert the link-to-existing modal is opened, not a blind retry.
Guard tests
ForrolesGuard and centerAdminGuard, test both the authorized and unauthorized path. Use routerMock.navigate to assert the redirect destination when the guard blocks access.
Test patterns at a glance
| Code type | Key assertions |
|---|---|
| Service | MainResponse<T> envelope shape; 409 conflict flow; HttpTestingController.verify() |
| Component | Role-conditional element presence; signal → DOM; form validity; error surface |
| Guard | Authorized path returns true; unauthorized path calls router.navigate |
| Interceptor | Header injection; error toast/alert dispatch; 409 modal trigger |
| Pipe | Pure transformation with edge cases (null, empty string, boundary values) |