“Uncaught [object Object]"当在Angular上运行karma测试时 [英] "Uncaught [object Object]" when running karma tests on Angular
问题描述
在为我的应用程序运行单元测试时,我正在与这个奇怪的错误作斗争。
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.
在出现错误之前我遇到了脚本错误错误,但我用 - 解决了 - 适用于ChromeHeadless的-disable-web-security标志。我不知道它是否与这个新错误有关。
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.
我的locale和遥控器都是linux。
Both my locale en the remote are linux.
推荐答案
您可能在远程或不同版本的全局npm软件包上安装了不同版本的模块。任何不匹配的依赖版本都会在任一台机器上产生不同的结果。
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.
在两台机器上清除你的npm缓存:
Purge your npm cache on both machines:
npm cache clean
重新安装 node_modules
:
rm -fr node_modules
npm install
验证每台机器上的本地npm包是否相同
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.
首先尝试运行业力
karma start
如果可行,则接下来分别运行每个测试。
If that works, next run each test separately.
karma run -- --grep=search_string
如果错误阻止你开始业力。检查启动脚本以获取测试,并查看是否可以从Angular应用程序中注释掉模块。继续减少依赖关系,直到你运行Karma。慢慢重新介绍依赖关系,直到找到罪犯。
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.
这篇关于“Uncaught [object Object]"当在Angular上运行karma测试时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!