angular: Production Unit Tests Intermittently Fail In afterAll with Uncaught [object Object]
🐞 bug report
Affected Package
ng test --prod
Is this a regression?
No?
Description
Intermittently we are seeing different unit tests fail on production configuration test runs.
WallabyJS does not fail (it doesn’t run production configuration).
ng test
does not fail.
ng test --prod
does fail intermittently on random tests.
It seems to never be the same test.
I can’t find anything common between the tests or the objects under test. Sometimes a service, sometimes a component.
🔬 Minimal Reproduction
There is no way to consistently reproduce an intermittent error that is happening in random unit tests.
🔥 Exception or Error
This is output from the TeamCity reporter:
HeadlessChrome 78.0.3904 (Mac OS X 10.14.6) ERROR
{
"message": "An error was thrown in afterAll\nUncaught [object Object] thrown",
"str": "An error was thrown in afterAll\nUncaught [object Object] thrown"
}
🌍 Your Environment
Angular Version:
Angular CLI: 8.0.2
Node: 10.16.0
OS: darwin x64
Angular: 8.0.0
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.800.2
@angular-devkit/build-angular 0.800.2
@angular-devkit/build-optimizer 0.800.2
@angular-devkit/build-webpack 0.800.2
@angular-devkit/core 7.3.6
@angular-devkit/schematics 8.0.2
@angular/cdk 8.0.1
@angular/cli 8.0.2
@angular/material 8.0.1
@angular/pwa 0.801.1
@angular/service-worker 8.1.1
@ngtools/webpack 8.0.2
@schematics/angular 8.0.2
@schematics/update 0.800.2
rxjs 6.5.2
typescript 3.4.5
webpack 4.30.0
Anything else relevant? This is happening locally as well as on our build agents.
{
"name": "my-med-study",
"version": "0.0.0",
"license": "UNLICENSED",
"private": true,
"scripts": {
"cypress:run": "cypress run --reporter teamcity",
"cypress:open": "./node_modules/.bin/cypress open",
"ng": "ng",
"ng-high-memory": "node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng",
"start": "ng serve",
"start:local": "ng serve -o --proxy-config proxy.conf.local.json",
"start:remote:ie": "ng serve --configuration es5 --host JKYMacbookProWork.local --port 4201 --disable-host-check",
"start:remote": "ng serve --host JKYMacbookProWork.local --port 4201 --disable-host-check",
"build:devdeploy": "ng build --configuration devdeploy",
"build:staging": "ng build --configuration staging",
"build:prod": "ng build --configuration production",
"test": "ng test",
"test:prod": "ng test --prod --watch false --code-coverage",
"lint": "ng lint",
"e2e": "ng e2e",
"e2e:local": "npm run e2e -- --configuration=local",
"e2e:local:api": "npm run e2e -- --configuration=localApi",
"mocked": "ng serve --configuration mastermock",
"ci:serve": "ng build --prod && http-server dist -p 4200",
"cypress:ci": "start-server-and-test ci:serve http://localhost:4200 cypress:run"
},
"dependencies": {
"@angular-devkit/core": "^7.3.6",
"@angular/animations": "^8.0.0",
"@angular/cdk": "~8.0.1",
"@angular/common": "^8.0.0",
"@angular/compiler": "^8.0.0",
"@angular/core": "^8.0.0",
"@angular/forms": "^8.0.0",
"@angular/material": "~8.0.1",
"@angular/platform-browser": "^8.0.0",
"@angular/platform-browser-dynamic": "^8.0.0",
"@angular/router": "^8.0.0",
"@angular/pwa": "^0.801.1",
"@angular/service-worker": "^8.0.0",
"@ngrx/effects": "^8.4.0",
"@ngrx/entity": "^8.4.0",
"@ngrx/store": "^8.4.0",
"@ngrx/store-devtools": "^8.4.0",
"@types/hammerjs": "^2.0.36",
"blob-util": "^2.0.2",
"configcat-js": "1.1.x",
"core-js": "^2.6.1",
"hammerjs": "^2.0.8",
"http-server": "^0.11.1",
"lodash": "^4.17.11",
"moment": "^2.23.0",
"ng2-dragula": "^2.1.1",
"ngx-cookie-service": "^2.2.0",
"ngx-infinite-scroll": "^7.0.1",
"reflect-metadata": "^0.1.12",
"rxjs": "^6.5.2",
"subsink": "^1.0.0",
"tslib": "^1.9.3",
"zone.js": "~0.9.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.800.0",
"@angular/cli": "^8.0.2",
"@angular/compiler-cli": "^8.0.0",
"@angular/language-service": "^8.0.0",
"@netbasal/spectator": "^3.1.3",
"@ngrx/schematics": "^7.0.0",
"@types/jasmine": "~3.3.5",
"@types/jasminewd2": "~2.0.6",
"@types/lodash": "^4.14.119",
"@types/node": "~10.10.1",
"angular2-template-loader": "^0.6.2",
"codelyzer": "^5.0.1",
"cypress": "^3.3.1",
"cypress-file-upload": "^3.1.2",
"cypress-teamcity-reporter": "^2.6.1",
"jasmine-core": "~3.3.0",
"jasmine-marbles": "^0.5.0",
"jasmine-reporters": "^2.3.2",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.1.4",
"karma-chrome-launcher": "~2.2.0",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^2.0.4",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"karma-teamcity-reporter": "^1.1.0",
"lint-staged": "^8.1.4",
"ng-mocks": "^8.0.0",
"ngx-spec": "^1.0.1",
"prettier": "^1.18.2",
"protractor": "~5.4.2",
"protractor-fail-fast": "^3.1.0",
"start-server-and-test": "^1.9.1",
"ts-node": "~7.0.1",
"tslint": "~5.12.0",
"tslint-defocus": "^2.0.6",
"typescript": "~3.4.0",
"wallaby-webpack": "^3.9.13"
}
}
Test config from angular.json:
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.js",
"styles": ["src/styles.scss"],
"scripts": [],
"assets": ["src/favicon.ico", "src/assets", "src/web.config", "src/manifest.json"],
"codeCoverageExclude": ["**/*.mock.ts", "**/*.module.ts"],
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/DO_NOT_IMPORT.ENVIRONMENT.UNITTESTING.ts"
}
]
},
"configurations": {
"production": {
"karmaConfig": "src/karma.conf.prod.js"
}
}
},
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 16 (7 by maintainers)
@shravansofts I’d advise you to run entire suite locally in regular chrome (not headless) and see dev tools console. I am 99.9% sure you will see an error there and it will have nothing to do with angular.
Personally such errors immediately suggest that some spec is not mocking properly and not using ‘done’ function param provided by jasmine.
I found a solution. I changed code to the following:
` it(‘error’, () => { const error = { error: state }; authService.getToken.and.returnValue(throwError(error));
`
No more “An error was thrown in afterAll” error.