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

后端 未结 17 2206
生来不讨喜
生来不讨喜 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:12

    What can help is, if you have the Chrome window open for your Karma test runner, to open the developer tools and check the console there. For me, this helped me to find out that the app could not use the Array.findIndex method on an undefined array (because the data structure was organized by a date string, such as data[2018][3][28], and I happened to be pointing to the wrong date), but yet instead of just stopping at the error, the test kept running.

    0 讨论(0)
  • 2020-12-04 10:14

    If sourcemap=false doesn't help, try to 1) open your browser running the tests 2) click debug button 3) open the console

    The error will be there

    0 讨论(0)
  • 2020-12-04 10:16

    For me the issue was that I had a test where I was accidentally using the auth0-lock library.

    0 讨论(0)
  • 2020-12-04 10:17

    In the end, what can worked for me:

        TestBed.resetTestingModule();
      })
    
    0 讨论(0)
  • 2020-12-04 10:18

    I had the same problem. One way this error happens is when you try to access anything null or undefined in template. Make sure you have safety checking on those variable.

    For example this will throw [object: ErrorEvent] when config is undefined on component load.

    template.html

    <div *ngIf="config.options">
       .....
       ......
    </div>
    

    Do this instead

    <div *ngIf="config?.options">
       .....
       ......
    </div>
    
    0 讨论(0)
提交回复
热议问题