Reputation: 825
I have the following problem: When I run unit/integration tests for my Angular project with Karma, there is like a 50:50 chance that my tests will succeed/fail. Mostly it works on my maschine (:D), but not on our build server and that makes it really unreliable at all.
When it fails, it is always a cryptic error message, which says
script error.
...nothing more. Now the strange thing about it is, that it is always another test which fails.
Here is what I already did or had a look at:
These are my dependencies:
"dependencies": {
"@angular/animations": "^6.0.9",
"@angular/cdk": "^6.4.0",
"@angular/common": "^6.0.9",
"@angular/compiler": "^6.0.9",
"@angular/core": "^6.0.9",
"@angular/flex-layout": "^6.0.0-beta.16",
"@angular/forms": "^6.0.9",
"@angular/http": "^6.0.9",
"@angular/material": "^6.4.0",
"@angular/platform-browser": "^6.0.9",
"@angular/platform-browser-dynamic": "^6.0.9",
"@angular/platform-server": "^6.0.9",
"@angular/router": "^6.0.9",
"@ngrx/effects": "^6.0.1",
"@ngrx/router-store": "^6.0.1",
"@ngrx/store": "^6.0.1",
"@ngrx/store-devtools": "^6.0.1",
"core-js": "^2.5.7",
"devextreme": "^18.1.4",
"devextreme-angular": "^18.1.4",
"i": "^0.3.6",
"jquery": "^3.3.1",
"ngx-scrollbar": "^2.1.0",
"node-sass": "^4.9.0",
"npm": "^6.2.0",
"rxjs": "^6.2.2",
"stream": "0.0.2",
"web-animations-js": "^2.3.1",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.6.3",
"@angular/cli": "^6.0.8",
"@angular/compiler-cli": "^6.0.9",
"@angular/language-service": "^6.0.9",
"@types/jasmine": "^2.8.8",
"@types/jasminewd2": "^2.0.3",
"@types/node": "^10.5.2",
"codelyzer": "^4.4.2",
"fs-extra": "^6.0.1",
"git-describe": "^4.0.3",
"gulp": "^4.0.0",
"gulp-param": "^1.0.3",
"gulp-run": "^1.7.1",
"hogan.js": "^3.0.2",
"husky": "^0.14.3",
"jasmine-core": "^3.1.0",
"jasmine-spec-reporter": "^4.2.1",
"jszip": "^3.1.5",
"karma": "^2.0.4",
"karma-chrome-launcher": "~2.2.0",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^2.0.1",
"karma-jasmine": "^1.1.2",
"karma-jasmine-html-reporter": "^1.2.0",
"license-checker": "^20.1.0",
"lint-staged": "^7.2.0",
"markdown-include": "^0.4.3",
"prettier": "^1.13.7",
"protractor": "^5.3.2",
"readline-sync": "^1.4.9",
"run-sequence": "^2.2.1",
"stylelint": "^9.3.0",
"stylelint-config-recommended-scss": "^3.2.0",
"stylelint-config-standard": "^18.2.0",
"stylelint-scss": "^3.1.3",
"ts-node": "^6.2.0",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.13.0",
"typescript": "2.7.2",
"yargs": "^11.1.0"
}
What should I do next ??
I appreciate every hint...thanks
Upvotes: 1
Views: 1438
Reputation: 825
I finally fixed the issue.
I somehow came on the right track and figured out, which test fails or rather is causing other tests to fail.
// causing part in the tests
beforeEach(() => {
fixture = TestBed.createComponent(FilterSidebarComponent);
component = fixture.componentInstance;
component.data = {} as DataClass;
fixture.detectChanges();
});
The problem was now, that inside a subscription in the component, I call a specific method of the class DataClass
:
this.attributeXY.subscribe(event => {
this.data.reset(); <-- reset() was undefined
if (event) {
// do something
...
}
})
The remaining question now is, why the cast of the empty object didn't work in this case?
My expectation was, that the method reset()
would be inferred as well
Upvotes: 0
Reputation: 135
From my experience, many times such random errors are due to a dirty state one of the test left behind which in turn fails some other test. AFAIK the default order for Karma is not expected or defined. I would try to comment out (binary search style) the first half of the tests and see if it passes consistently.
Upvotes: 2