首页 > 解决方案 > 随机:在 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",

标签: angularkarma-runner

解决方案


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({})),
})

推荐阅读