angular - 随机:在 afterAll TypeError 中引发错误:您在预期流的位置提供了“未定义”
问题描述
不时由于无法解释的原因 karma,返回一个难以调试的错误:
An error was thrown in afterAll
TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
at <Jasmine>
at subscribeTo (http://localhost:9876/_karma_webpack_/node_modules/rxjs/_esm5/internal/util/subscribeTo.js:28:1)
at subscribeToResult (http://localhost:9876/_karma_webpack_/node_modules/rxjs/_esm5/internal/util/subscribeToResult.js:15:23)
at MergeMapSubscriber._innerSub (http://localhost:9876/_karma_webpack_/node_modules/rxjs/_esm5/internal/operators/mergeMap.js:74:50)
at MergeMapSubscriber._tryNext (http://localhost:9876/_karma_webpack_/node_modules/rxjs/_esm5/internal/operators/mergeMap.js:68:1)
at MergeMapSubscriber._next (http://localhost:9876/_karma_webpack_/node_modules/rxjs/_esm5/internal/operators/mergeMap.js:51:1)
at MergeMapSubscriber.Subscriber.next (http://localhost:9876/_karma_webpack_/node_modules/rxjs/_esm5/internal/Subscriber.js:53:1)
at FilterSubscriber._next (http://localhost:9876/_karma_webpack_/node_modules/rxjs/_esm5/internal/operators/filter.js:38:1)
at FilterSubscriber.Subscriber.next (http://localhost:9876/_karma_webpack_/node_modules/rxjs/_esm5/internal/Subscriber.js:53:1)
at SafeSubscriber.__tryOrUnsub (http://localhost:9876/_karma_webpack_/node_modules/rxjs/internal/Subscriber.js:205:1)
at SafeSubscriber.next (http://localhost:9876/_karma_webpack_/node_modules/rxjs/internal/Subscriber.js:143:1)
你们中的任何人都知道如何跟踪它所关注的内容吗?
利用:
Angular 9
"jasmine-core": "^3.5.0",
"jasmine-marbles": "^0.6.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^4.4.1",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~2.1.1",
"karma-jasmine": "~3.1.1",
"karma-jasmine-html-reporter": "^1.5.2",
"karma-scss-preprocessor": "^4.0.0",
解决方案
在karma.conf.js
您的插件中添加require('karma-spec-reporter')
并在您的记者中添加spec
. 这应该列出每个测试成功/失败以及错误消息。
这应该可以帮助您确定哪些测试会引发此错误。
就我而言,即使afterAll
我的单元测试文件中没有语句,我也看到了错误。
mergeMap
在我的具体情况下,在测试用于按顺序组合两个可观察对象(一个可观察对象的输出成为另一个可观察对象的输入)的方法时会发生错误,然后一切都会发生.pipe(map(...),map(...))
。单元测试依赖于一个没有处理pipe()
以前在我的service.mock.ts
我有:
get: jasmine.createSpy('get').and.returnValue({
pipe: jasmine.createSpy('pipe'),
})
错误消失了:
get: jasmine.createSpy('get').and.returnValue({
pipe: jasmine.createSpy('pipe').and.returnValue(of({})),
})
推荐阅读
- microservices - 如果在 Eureka 服务器上注册的同一服务的多个实例之一出现故障会发生什么?
- excel - 嵌套用于创建报告
- python - 如何测试一个类及其方法
- r - 使用 R 在 lapply() 中应用 Magrittr 管道
- javascript - 无法从数组中过滤对象
- javascript - 在fabricJS中以相同的左原点缩放时保持相同的对象大小
- unix - Unix 树按模式忽略
- python - 将套接字从电子 UI 连接到 python 服务器时出现错误 400(错误请求)
- docker - 如何在 Azure ML 管道中正确指定私有 ACR Docker 映像?
- elasticsearch - 自动化 Kibana 仪表板创建