How do I debug a “[object ErrorEvent] thrown” error in my Karma/Jasmine tests?

后端 未结 17 2309
生来不讨喜
生来不讨喜 2020-12-04 09:51

I have several failing tests that only output [object ErrorEvent] thrown. I don\'t see anything in the console that helps me pinpoint the offending code. Is t

17条回答
  •  清歌不尽
    2020-12-04 10:04

    This is because the jasmine framework can not handle the ErrorEvent type so it does not extract the error message and calls error.toString() on that object instead.

    I just filed an issue at jasmine repo https://github.com/jasmine/jasmine/issues/1594

    As long as it is not fixed, you can temporarily patch your installed jasmine package in the node_modules folder. In my case it is

    node_modules/jasmine/node_modules/lib/jasmine-core/jasmine.js

    and then change the implementation of the ExceptionFormatter from this

    if (error.name && error.message) {
        message += error.name + ': ' + error.message;
    } else {
        message += error.toString() + ' thrown';
    }
    

    to this

    if (error.name && error.message) {
        message += error.name + ': ' + error.message;
    } else if (error.message) {
        message += error.message;
    } else {
        message += error.toString() + ' thrown';
    }
    

    It helps to identify the issue.

提交回复
热议问题