Issue
After updating to Angular 13, lots of my unit tests, that were running without problems on Angular 12, are now failing. What I found more frustrating is that the tests are failing only when running together, but not when I isolate them with fdescribe
.
I've read that in Angular 13, the teardown
options is set to true per default, so I tried to opt out globally in my test.ts
file:
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting(), {
teardown: { destroyAfterEach: false }
}
);
But this didn't work.
My Karma config:
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-junit-reporter'),
require('karma-coverage'),
require('karma-mocha-reporter'),
require('@angular-devkit/build-angular/plugins/karma'),
],
client: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
jasmine: {
random: false,
},
},
coverageReporter: {
dir: require('path').join(__dirname, '../../coverage/cockpit'),
reporters: [
{ type: 'html', subdir: 'report-html' },
{ type: 'lcov', subdir: 'report-lcov' },
{ type: 'text-summary' },
],
fixWebpackSourcePaths: true,
},
junitReporter: {
outputDir: require('path').join(__dirname, '../../junit-report/cockpit'),
suite: 'cockpit',
outputFile: 'cockpit-tests-report.xml',
fixWebpackSourcePaths: true,
},
reporters: ['mocha', 'kjhtml', 'coverage', 'junit'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true,
});
};
In the browser console I see lots of the following error:
NG0303: Can't bind to 'ngTemplateOutlet' since it isn't a known property of 'ng-container'
I'm running out of ideas.
Solution
The problem was caused by the ngrx store. It is now required to reset the selectors in the afterEach
block
afterEach(() => {
store.resetSelectors();
fixture.destroy();
TestBed.resetTestingModule();
});
Answered By - Motassem Jalal
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.