Recently, I made the transition from Angular 2 to 5 for a project and encountered an issue where test cases related to compiling views started failing. Tests that were previously successful are now not working as expected.
In order to troubleshoot the problem, I decided to create a simple test to identify the root cause:
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [Component],
imports: [MatCardModule] //Issues arise when this import is present (e.g. SharedModule)
});
TestBed.compileComponents(); //Fails once this is executed
}));
it('should display something',
expect("").toContain("");
});
When the mentioned import is included, no error is displayed but it does not execute any further test cases. If the import is excluded, it prompts me to confirm whether Mat-Card is part of the module.
Below is a snippet from the package.json file (Karma was recently updated):
"jasmine-core": "^3.1.0",
"jasmine-spec-reporter": "^4.2.1",
"karma": "^2.0.2",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.2",
"karma-jasmine": "^1.1.2",
"karma-mocha-reporter": "^2.2.5",
"karma-remap-istanbul": "^0.6.0",
"karma-systemjs": "^0.16.0"
UPDATE
After conducting some research, I suspect that the issue lies within the Karma configuration.
I managed to work around the MatCardModule problem by adding
schemas: [CUSTOM_ELEMENTS_SCHEMA]
to the TestBed. However, when introducing providers, it functioned with basic classes that did not require imports, whereas more complex ones (e.g. ObservableMedia) failed even if the necessary imports were provided. No errors were reported, and none of the tests were executed.