“Uncaught [object Object]” when running karma tests on Angular

社会主义新天地 提交于 2019-12-07 15:39:23

问题


I am fighting with this strange error when running unit tests for my application.

zone.js:260 Uncaught [object Object] thrown
Zone.runTask @ zone.js:260
ZoneTask.invoke @ zone.js:423

I dont know which test is failing cause the console only drop that error. It is not hapenning in my local, where the tests run whithout any problem.

Before that error i was suffering the "Script error" error but I solved it with the --disable-web-security flag for ChromeHeadless. I dont know if it has something to do with this new error.

Both my locale en the remote are linux.


回答1:


You might have different versions of modules installed on the remote, or different versions of global npm packages. Any mismatched version of dependency can yield a different result on either machine.

Purge your npm cache on both machines:

npm cache clean

Reinstall your node_modules on both machines:

rm -fr node_modules
npm install

Verify the local npm packages are the same on each machine

npm list --depth=0

Verify global package versions are the same. You can list global packages like this

 npm list -g --depth=0

Once you have everything the same. You should see the same result on both machines.

Start by trying to run karma

  karma start

If that works, next run each test separately.

  karma run -- --grep=search_string

If the error is preventing you from starting karma. Check the startup scripts for tests, and see if you can comment out modules from your Angular app. Keep reducing the dependencies until you get Karma running. Reintroduce the dependencies slowly until you find the offender.



来源:https://stackoverflow.com/questions/47873996/uncaught-object-object-when-running-karma-tests-on-angular

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!