I just migrated an application module to be an importable library.
I\'m trying to make the tests work correctly, just as they worked before, but I get this error:
At last, I found where the problem was, I had a hard time finding it because it was not related. The problem comes from this tslint configuration:
tslint.json:
...
"ordered-imports" [
true,
{ "named-imports-order": "lowercase-last" }
]
...
Even if the configuration is only "ordered-imports": true
it was causing a problem in test.ts
file when ng lint
is launched, so I changed that file to fulfill the tslint requirement:
test.ts:
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
import 'core-js/es7/reflect'; // <-- Moved from the top of imports
import 'zone.js/dist/zone'; // <-- Moved from the top of imports
import 'zone.js/dist/zone-testing'; // <-- Moved from the top of imports
declare const require: any;
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);
And this file was causing the error I was getting. This file must look like this:
Correct test.ts:
import 'core-js/es7/reflect';
import 'zone.js/dist/zone';
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
declare const require: any;
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);