Within our Angular project, we have a ./src/test.ts file that is responsible for loading all spec files to run under test with Karma and Jasmine:
// This file is necessary for karma.conf.js and recursively loads all .spec and framework files
import 'zone.js/testing';
import { getTestBed } from '@angular/core/testing';
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
declare const require: {
context(path: string, deep: boolean, filter?: RegExp): {
keys(): string[];
<T>(id: string): T;
};
};
// Initializing the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting(), {
teardown: { destroyAfterEach: false }
}
);
// Finding and running all tests.
const context = require.context('./', true, /\.spec\.ts$/);
// Loading the modules.
context.keys().forEach(context);
SonarQube has pointed out that this code is not covered by tests. How can we address this issue?