now test.ts
is generated by angular (node_modules/@angular-devkit/build-angular/src/builders/karma/index.js
), if you want to customize it, you need to do the next:
create src/test.ts
and put there:
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';
// Initialize the Angular testing environment.
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), {
errorOnUnknownElements: true,
errorOnUnknownProperties: true
});
Then add it to angular.json
:
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts", // <- here
"polyfills": [
"zone.js",
"zone.js/testing"
],
"tsConfig": "tsconfig.spec.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
}
}
}
and add it to tsconfig.spec.ts
:
"include": [
"src/test.ts", // <- here
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
profit, now you can extend test.ts
again.