Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests breaks after upgrading jasmine-core from 2.99.0 to 3.1.0 #1523

Closed
JonWallsten opened this issue Mar 6, 2018 · 29 comments
Closed

Tests breaks after upgrading jasmine-core from 2.99.0 to 3.1.0 #1523

JonWallsten opened this issue Mar 6, 2018 · 29 comments
Labels

Comments

@JonWallsten
Copy link

JonWallsten commented Mar 6, 2018

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"
  }
}
@slackersoft
Copy link
Member

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!

@JonWallsten
Copy link
Author

JonWallsten commented Mar 12, 2018

@slackersoft Ah,I see! I saw you finally got a reply there a couple of days back.

@rmsmq
Copy link

rmsmq commented Apr 4, 2018

I am also having this issue. Are we essentially waiting for @slackersoft changes to be released in karma-jasmine?

@slackersoft
Copy link
Member

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!

@robvaneck
Copy link

robvaneck commented May 16, 2018

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:


 10% building modules 1/1 modules 0 active16 05 2018 10:47:23.649:WARN [karma]: No captured browser, open http://localhost:9876/
16 05 2018 10:47:23.660:INFO [karma]: Karma v2.0.2 server started at http://0.0.0.0:9876/
16 05 2018 10:47:23.661:INFO [launcher]: Launching browser Chrome with unlimited concurrency
16 05 2018 10:47:23.668:INFO [launcher]: Starting browser Chrome
16 05 2018 10:47:30.338:WARN [karma]: No captured browser, open http://localhost:9876/  
16 05 2018 10:47:30.496:INFO [Chrome 66.0.3359 (Mac OS X 10.13.4)]: Connected on socket 4yMxIms1uAC0jI69AAAA with id 45005496
Chrome 66.0.3359 (Mac OS X 10.13.4) ERROR
  {
    "message": "An error was thrown in afterAll\n[object ErrorEvent]",
    "str": "An error was thrown in afterAll\n[object ErrorEvent]"
  }
Chrome 66.0.3359 (Mac OS X 10.13.4): Executed 0 of 0 ERROR (0 secs / 0 secs)
Chrome 66.0.3359 (Mac OS X 10.13.4) ERROR
  {
    "message": "An error was thrown in afterAll\n[object ErrorEvent]",
    "str": "An error was thrown in afterAll\n[object ErrorEvent]"
Chrome 66.0.3359 (Mac OS X 10.13.4): Executed 0 of 0 ERROR (0.013 secs / 0 secs)
^C
MacBook-Pro:fe user$ 

package.json

{
  "name": "project",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --host 0.0.0.0 --proxy-config proxy.conf.json",
    "build": "ng build --prod --output-hashing none",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^5.0.0",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/router": "^5.0.0",
    "@types/jasmine": "^2.8.7",
    "bootstrap": "^4.1.1",
    "core-js": "^2.5.6",
    "karma-jasmine": "^1.1.2",
    "keycloak-js": "3.4.3",
    "lodash": "^4.17.10",
    "ng2-slim-loading-bar": "^4.0.0",
    "ng2-toastr": "^4.1.2",
    "ngx-bootstrap": "^2.0.5",
    "protractor": "^5.3.2",
    "rxjs": "^5.5.2",
    "svgxuse": "^1.2.6",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "1.7.2",
    "@angular/compiler-cli": "^5.0.0",
    "@angular/language-service": "^5.0.0",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~9.4.6",
    "codelyzer": "^4.3.0",
    "jasmine-core": "^3.1.0",
    "jasmine-spec-reporter": "^4.2.1",
    "karma": "^2.0.0",
    "karma-chrome-launcher": "^2.2.0",
    "karma-cli": "^1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "^1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "^5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "^5.10.0",
    "typescript": "^2.8.3"
  }
}

what do we need to do?

When i downgrade to jasmine-core: "^2.9.0" the tests do run

@kloasn
Copy link

kloasn commented May 16, 2018

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.

@sgravrock
Copy link
Member

@borriej The reporter interface changed in Jasmine 3.0, and several of the package versions you're using only work with the old interface. Right now it looks like you have two options. One is to stay on Jasmine 2.x for now. The other is to upgrade karma-jasmine and karma-jasmine-html-reporter and remove jasmine-spec-reporter, which hasn't been updated to work with Jasmine 3 yet.

@ddubson
Copy link

ddubson commented Jun 4, 2018

I ran into this issue as well, and the comment above led me to the fact that I did have a reporter configuration file in my tests directory. I excluded that file from the included test files that the browser loads (karma.conf.js -> exclude: [...], and the issue is no more. Running with Jasmine 3.1.0

@slackersoft
Copy link
Member

The newest version of Karma-Jasmine includes support for Jasmine 3.x and the new reporter interface. You should look at updating that as well if you're using Karma already. If you have a custom reporter that is having issues, take a look at the 3.0 release notes for a bit more information on what changed in the reporting structure.

Hope this helps. Thanks for using Jasmine!

@harpcio
Copy link

harpcio commented Jun 28, 2018

My problem was caused by using "this.router.navigate(['/login']);" in ngOnInit method in completely other component.
In your tests you need to specify:

                RouterTestingModule.withRoutes([
                    { path: 'login', component: LoginComponent }
                ]),

and put this formula into "imports", and also "LoginComponent" into "declarations".

@sopretty
Copy link

sopretty commented Jul 11, 2018

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 :

import 'core-js/es7/reflect';
import 'zone.js/dist/zone';

@ilancohen
Copy link

@sopretty - which polyfills did you use?
And/or where did you add those two lines? In test.ts? I tried that, and the tests simply didn't run.

@sopretty
Copy link

@ilancohen
I changed few things :

  • the angular.json of the project.
    For each libraries, I set up my test environment :
[...]
     "test": {
                    "builder": "@angular-devkit/build-angular:karma",
                    "options": {
                        "polyfills": "projects/my-lib/src/polyfills.ts",
                        "main": "projects/my-lib/src/test.ts",
                        "tsConfig": "projects/my-lib/tsconfig.spec.json",
                        "karmaConfig": "projects/my-lib/karma.conf.js"
                    }
                },
[...]
  • tsconfig.spec.json of a specific project :
{
    "extends": "../../tsconfig.json",
    "compilerOptions": {
        "outDir": "../../out-tsc/spec",
        "types": [
            "jasmine",
            "node"
        ]
    },
    "files": [
        "src/test.ts",
        "src/polyfills.ts"
    ],
    "include": [
        "**/*.spec.ts",
        "**/*.d.ts"
    ]
}
  • polyfills.ts of a specific project :
    I added this two lines to all polyfills I need to import.
import 'core-js/es7/reflect';
import 'zone.js/dist/zone';

@slackersoft
Copy link
Member

It sounds like this issue has been resolved and the remaining points are configuration of the upgrade of Karma/Angular with the new versions of Jasmine. I'm going to close this.

Thanks for using Jasmine!

@fabiendv
Copy link

I have still the same error even if I made some changes.

Chrome 68.0.3440 (Linux 0.0.0) ERROR
  {
    "message": "An error was thrown in afterAll\nUncaught TypeError: env.hideDisabled is not a function",
    "str": "An error was thrown in afterAll\nUncaught TypeError: env.hideDisabled is not a function"

Every packages are updated, I don't understand

@plakhtiin
Copy link

@F-DALLA-VALLE Do you have some external scripts into your index.html? I think problem can be there.

@fabiendv
Copy link

I uninstalled and installed every packages, and it's working now.

Thank for your help,

@fabiendv
Copy link

It happened again,
I do not have external scripts in my index.html
Sometimes it works (when I launch my ng command), I don't understand why.

@fabiendv
Copy link

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

@jahller
Copy link

jahller commented Sep 10, 2018

To whom it may concern, we had a similar issue:

Chrome 70.0.3508 (Mac OS X 10.13.6) ERROR
  {
    "message": "An error was thrown in afterAll\n[object ErrorEvent]",
    "str": "An error was thrown in afterAll\n[object ErrorEvent]"
  }

problem was a test failing silently, which was ultimately found out by running Chrome with singleRun=false and checking the reports in the Jasmine UI.

@Ruluk
Copy link

Ruluk commented Oct 16, 2018

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.

@tapaz1
Copy link

tapaz1 commented Jan 7, 2019

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.

  • Run your tests and enable watch (i.e. watch=true) if disabled, and remove the "headless" flag (if included in your karma.conf.js file) if you are using it (you'll need to see the console in the browser).

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 🍺

@dmiko1994
Copy link

dmiko1994 commented Aug 9, 2019

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.

@adisreyaj
Copy link

I've recently faced this same issue and couldn't actually figure out why until i actually dived into the console logs that Karma was putting out. These problems can be caused due to multiple problems.

So the best way to find out why is to actually run it in Chrome, a dive into the console logs to debug the issue. For me it was a filtering function were i was using toLowerCase().

@ghost
Copy link

ghost commented Dec 6, 2019

@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.

@danbilokha
Copy link

To whom it may concern, we had a similar issue:

Chrome 70.0.3508 (Mac OS X 10.13.6) ERROR
  {
    "message": "An error was thrown in afterAll\n[object ErrorEvent]",
    "str": "An error was thrown in afterAll\n[object ErrorEvent]"
  }

problem was a test failing silently, which was ultimately found out by running Chrome with singleRun=false and checking the reports in the Jasmine UI.

still 3 years after the suggestion it has helped to solve the issue.
My case was that for some reason before 3.10 test with hanging subscription was not failing, afterwards it became flaky.

So the solution was to find test which had subscription w/o TestScheduler or done() or fakeAsync to me

@ashkan-dev-86
Copy link

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.

Thank you
This resolved the issue I was searching for one day

@eliBlooma
Copy link

For me upgrading puppeteer to version 18 solved the issue.

@FEDEX91
Copy link

FEDEX91 commented Nov 9, 2022

import 'core-js/es7/reflect';
import 'zone.js/dist/zone';

Hi, you included these imports into karm.conf.js or in test.ts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests