jasmine: Tests breaks after upgrading jasmine-core from 2.99.0 to 3.1.0
Expected Behavior
I’m running Angular 5 test cases with karma/jasmine. The test should succeed but fails. Can’t really tell which package is responsible for the actual bug. But he bug occurred after upgrading jasmine-core from 2.99.0 -> 3.1.0. If you think this bug is related to Karma or any other package, please tell so and feel free to close it.
Current Behavior
I have an Angular 5 project running karma/jasmine. Unfortunately the tests stopped working after upgrading from 2.99.0 to 3.1.0 with this ambiguous error.
Chrome 64.0.3282 (Windows 10.0.0) ERROR
{
"message": "An error was thrown in afterAll\n[object ErrorEvent]",
"str": "An error was thrown in afterAll\n[object ErrorEvent]"
}
Chrome 64.0.3282 (Windows 10.0.0): Executed 1 of 1 ERROR (0 secs / 0 secs)
Chrome 64.0.3282 (Windows 10.0.0) ERROR
{
"message": "An error was thrown in afterAll\n[object ErrorEvent]",
"str": "An error was thrown in afterAll\n[object ErrorEvent]"
Chrome 64.0.3282 (Windows 10.0.0): Executed 1 of 1 ERROR (0.187 secs / 0 secs)
Possible Solution
None. I’m happy to help debugging the issue. But my knowledge of karma/jasmine is to limited to do without assistance.
Suite that reproduces the behavior (for bugs)
import { async, TestBed } from '@angular/core/testing';
import { StartComponent } from './start.component';
describe('StartComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
StartComponent
],
}).compileComponents();
}));
it('should create the app', async(() => {
const fixture = TestBed.createComponent(StartComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
}));
});
Your Environment
- Version used: 3.1.0
- Environment name and version (e.g. Chrome 39, node.js 5.4): Chrome 64, Node 8.9.4,
- Operating System and version (desktop or mobile): Dekstop
{
"devDependencies": {
"@angular/cli": "6.0.0-beta.4",
"@angular/compiler-cli": "6.0.0-beta.6",
"@types/jasmine": "2.8.6",
"@types/jasminewd2": "2.0.3",
"@types/node": "8.0.19",
"@types/webpack": "3.8.8",
"awesome-typescript-loader": "3.5.0",
"css-loader": "0.28.10",
"extract-text-webpack-plugin": "4.0.0-beta.0",
"html-loader": "0.5.5",
"html-webpack-plugin": "^3.0.4",
"husky": "0.14.3",
"jasmine-core": "^2.99.0",
"jasmine-spec-reporter": "4.2.1",
"karma": "2.0.0",
"karma-chrome-launcher": "2.2.0",
"karma-coverage-istanbul-reporter": "1.4.1",
"karma-jasmine": "1.1.1",
"karma-jasmine-html-reporter": "0.2.2",
"less": "3.0.1",
"less-loader": "4.0.6",
"postcss": "6.0.19",
"postcss-cssnext": "3.1.0",
"postcss-easy-import": "3.0.0",
"postcss-load-plugins": "2.3.0",
"postcss-loader": "2.1.1",
"protractor": "^5.3.0",
"puppeteer": "1.1.1",
"serve": "6.5.1",
"style-loader": "0.20.2",
"to-string-loader": "1.1.5",
"ts-node": "5.0.1",
"tslint": "5.9.1",
"tslint-config-standard": "7.0.0",
"tslint-eslint-rules": "5.1.0",
"typescript": "2.6.2",
"uglifyjs-webpack-plugin": "1.2.2",
"webpack": "4.1.0",
"webpack-cli": "^2.0.10",
"webpack-dev-server": "3.1.0",
"write-file-webpack-plugin": "4.2.0"
},
"dependencies": {
"@angular/animations": "6.0.0-beta.6",
"@angular/common": "6.0.0-beta.6",
"@angular/compiler": "6.0.0-beta.6",
"@angular/core": "6.0.0-beta.6",
"@angular/forms": "6.0.0-beta.6",
"@angular/http": "6.0.0-beta.6",
"@angular/language-service": "6.0.0-beta.6",
"@angular/platform-browser": "6.0.0-beta.6",
"@angular/platform-browser-dynamic": "6.0.0-beta.6",
"@angular/router": "5.2.7",
"angular": "1.6.9",
"core-js": "2.5.3",
"rxjs": "5.5.6",
"zone.js": "0.8.20"
}
}
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 42
- Comments: 29 (5 by maintainers)
Commits related to this issue
- chore: downgrade jasmine-core from 3.1.0 to 2.99.1 because of failing test run, see jasmine/jasmine#1523 — committed to nlnwa/veidemann-dashboard by maeb 6 years ago
- downgrade jasmine-core to fix tests, see jasmine/jasmine#1523 — committed to skycoin/skycoin-web by AlexSugak 6 years ago
I submitted a pull request (karma-runner/karma-jasmine#192) to karma-jasmine a few weeks ago to add support for Jasmine 3.x, but it hasn’t seen attention from the maintainers there. We changed some of the mechanisms for reporting some errors in 3.0, so it might be related to that.
Hope this helps. Thanks for using Jasmine!
For those still having this issue I would suggest the following since most of the proposed answers here didn’t resolve the problem our team was facing.
Someone suggested to look in the console for errors in a related post in stack overflow and I cannot stress enough how simple and helpful this is.
The issue for our team was that we are using a directive in a dummy component in our spec file, but the dummy component was missing the id for the resizeHandle in the directive, which is used to create an observable stream of mouse events (see below)
export class ResizableDirective implements AfterViewInit, OnDestroy {@Input('attr.resize-handle') private resizeHandle;private mouseUp$: Observable<MouseEvent | Event>;private mouseDown$: Observable<any>;private mouseMove$: Observable<MouseEvent | Event>;private subscription: Subscription;constructor(@Inject(DOCUMENT) private document,private element: ElementRef,private renderer: Renderer2) { }ngAfterViewInit() {this.mouseMove$ = fromEvent(this.document, 'mousemove');this.mouseUp$ = fromEvent(this.document, 'mouseup');this.mouseDown$ = fromEvent(this.resizeHandle, 'mousedown').map((event: MouseEvent) => {event.stopPropagation();const offset = this.calculateOffset(event);return this.mouseMove$.map((moveEvent: MouseEvent) => {moveEvent.stopPropagation();moveEvent.preventDefault();return this.calculatePosition(offset, moveEvent);}).takeUntil(this.mouseUp$);}).flatMap(_ => _);}}The bold code above wound up throwing this error ⇓
{ "message": "An error was thrown in afterAll\n[object ErrorEvent]", "str": "An error was thrown in afterAll\n[object ErrorEvent]" }So, the most logical and helpful answer is to look at the console in the browser because it will give you hints with the trace and call stack as to what could possibly be going wrong. Fixing the dummy component to include the “resizeHandle” fixed it being undefined and throwing the silent error, which was visible in the browser.
Also, it looks like as of v2.0.0 karma-jasmine fixes the obscure error thrown and possibly bubbles up a more useful error for those using an older version of karma-jasmine (like we were).
Hope this helps others find a path to resolving this error!
Cheers 🍺
To whom it may concern, we had a similar issue:
problem was a test failing silently, which was ultimately found out by running Chrome with
singleRun=falseand checking the reports in the Jasmine UI.For anyone who is still struggling even after trying proposed solutions on here (like me), this might be worth a check for you:
My tests were succeeding locally with no warnings or errors. When I pushed up to the remote, our CI server (Jenkins) was failing those tests and giving a terribly cryptic, awful error message that is listed above in the OPs comment. After 90 minutes or so of googling, I finally found my problem. I was using HttpClientModule in my imports for one of my tests. In ngOnInit() of the component I was testing, I was making service calls which were failing but giving me said terrible error message. When googling I saw a whole bunch of people proposing to upgrade/downgrade jasmine and that seemed to be the universal solution. After trying multiple proposed versions of jasmine, I did some more googling. I found one person at the very bottom of a thread suggesting to check for use of HttpClientModule in tests instead of HttpClientTestingModule. Sure enough I had 1 component.spec.ts out of like 75 importing HttpClientModule and it was failing my build and giving me that awful message without telling me which test failed. Pretty annoying. Still not sure why it worked locally but not on Jenkins.
Until there’s a new karma-jasmine version that supports some of the new features in Jasmine 3.0, there’s not much for us to look into here. I’m keeping this issue open in case there are some other issues that aren’t resolved by updating karma-jasmine.
Hope this helps. Thanks for using Jasmine!
@adisreyaj thanks for the answer! This helped a lot, because I had just switched to running headless Chrome to make things faster but it looks like a regular browser is needed for local development in order to find these weird test failures.
I see that same error message from @jahller. I’ve noticed it is somehow related to concurrency, because it does not happen in the same tests, every now and then all tests manage to pass, and the more tests, the more often it happens.
I’ve also noticed that when trying multiple browsers, IE breaks the most, almost always.
There was just a dependencies issues in my package.json I updated everything, (jasma core , karma , … ) , It’s working now. Sorry about that, thanks for your help
@ilancohen I changed few things :
I had the same issue with a library project with angular 6. And I fixed it with polyfills inside the karma.conf file of my project.
You maybe need to add this two lines :
My problem was caused by using “this.router.navigate([‘/login’]);” in ngOnInit method in completely other component. In your tests you need to specify:
and put this formula into “imports”, and also “LoginComponent” into “declarations”.
Since the error message is rather obscure I don’t know if it helps here, but what helped in my case was removing test.js from the files section in karma,conf.js.
After also moving karma.conf.js to the /src folder and changing the path to this file in angular.json I got it to work with jasmine 3.1.0. This is also how it gets generated if you do ng new.
Im also getting this issue when running
npm test😦 all the unit test code in the *.spec files have been commented out for debug purpose… and I get this:package.json
what do we need to do?
When i downgrade to
jasmine-core: "^2.9.0"the tests do run