Karma: [object ErrorEvent] thrown

Created on 16 Nov 2017  路  7Comments  路  Source: karma-runner/karma

Expected behaviour

Actual behaviour

Environment Details

dev dependency -

"@angular/core": "^4.0.0",
"@angular/cli": "1.2.4",
"@angular/compiler-cli": "^4.0.0",
"istanbul-instrumenter-loader": "^2.0.0",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage": "^1.1.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-phantomjs-launcher": "^1.0.2",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^1.8.0",

  • Karma version (output of karma --version):
  • Relevant part of your karma.config.js file

Steps to reproduce the behaviour


  1. 2.
    3.

Most helpful comment

Ok I was able to reproduce what I think is reported here. A test like this will show it:

it('throws ErrorEvent', function() {
    throw new ErrorEvent('a message here');
});

Ultimately this is a bug in the code that threw the ErrorEvent: don't do that. An ErrorEvent is not an Error.

Jasmine test framework analyzes the error object in its ExceptionFormatter:
https://github.com/jasmine/jasmine/blob/8624a52ee0b6f13b3b608ea6417ccc02257c5412/src/core/ExceptionFormatter.js#L9
and that is where the "thrown" part of the message comes from.

What you can do is edit your copy of jasmine, find the ExceptionFormatter where it calls toString() on the error object, and add a line like:

console.error('not-an-error-error', error);

Then run karma with --no-single-run and open the Debug page and open chrome devtools. When you run your tests you will see the ErrorEvent object printed by chrome-devtools. That may give you enough of a hint so you can find where it is being called.

All 7 comments

No steps to reproduce, please try again.

https://stackoverflow.com/questions/47832121/object-errorevent-thrown-jasmine
https://stackoverflow.com/questions/47828730/object-errorevent-thrown-in-angular-app-testing

Hi,

I am getting below error, object ErrorEvent thrown jasmine if i try to run individual file from karma this error is not appearing, but when i run with all spec files it is throwing above error the configuration of files is done in karma

All files configuration --- const context = require.context('./', true, /.spec.ts$/);

single file configuration --- const context = require.context('./', true, /app.comp.spec.ts$/);

angular karma & jasmine version :
"@angular/cli": "1.2.4", "@angular/compiler-cli": "^4.0.0", "@angular/language-service": "^4.0.0", "karma": "~1.7.0", "karma-chrome-launcher": "~2.1.1", "karma-cli": "~1.0.1", "karma-coverage-istanbul-reporter": "^1.2.1", "karma-jasmine": "~1.1.0", "karma-jasmine-html-reporter": "^0.2.2", "@types/jasmine": "~2.5.53", "@types/jasminewd2": "~2.0.2", "jasmine-core": "~2.6.2", "jasmine-spec-reporter": "~4.1.0",

Plz help me to resolve this issue

@gajusp are using ng-cli? Did u try disable the sourcemaps? ng t -sm=false

yes tried this one as well

"test": "ng test --sourcemaps=false",

still facing same issue

Where are you seeing this error? In the nodejs console window? Can you paste the surrounding text? Or are you seeing this in the browser?

Ok I was able to reproduce what I think is reported here. A test like this will show it:

it('throws ErrorEvent', function() {
    throw new ErrorEvent('a message here');
});

Ultimately this is a bug in the code that threw the ErrorEvent: don't do that. An ErrorEvent is not an Error.

Jasmine test framework analyzes the error object in its ExceptionFormatter:
https://github.com/jasmine/jasmine/blob/8624a52ee0b6f13b3b608ea6417ccc02257c5412/src/core/ExceptionFormatter.js#L9
and that is where the "thrown" part of the message comes from.

What you can do is edit your copy of jasmine, find the ExceptionFormatter where it calls toString() on the error object, and add a line like:

console.error('not-an-error-error', error);

Then run karma with --no-single-run and open the Debug page and open chrome devtools. When you run your tests you will see the ErrorEvent object printed by chrome-devtools. That may give you enough of a hint so you can find where it is being called.

Was this page helpful?
0 / 5 - 0 ratings