7

我创建了角度为 5.2.0 的 c3 条形图。一切正常。但我只想使用 karma 和 jasmine 运行测试npm run test。但是我遇到了以下问题。我希望它与 rxjs 功能有关。但我无法理解错误核心。请帮助任何人解决这个问题。

TypeError: _this.handler.handle is not a function
    at MergeMapSubscriber.project (http://localhost:9876/_karma_webpack_/webpack:/C:/Workspace/datawens-master/node_modules/@angular/common/esm5/http.js:1466:80)
    at MergeMapSubscriber.webpackJsonp.../../../../rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._tryNext (http://localhost:9876/_karma_webpack_/webpack:/C:/Workspace/datawens-master/node_modules/rxjs/_esm5/operators/mergeMap.js:128:1)
    at MergeMapSubscriber.webpackJsonp.../../../../rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._next (http://localhost:9876/_karma_webpack_/webpack:/C:/Workspace/datawens-master/node_modules/rxjs/_esm5/operators/mergeMap.js:118:1)
    at MergeMapSubscriber.webpackJsonp.../../../../rxjs/_esm5/Subscriber.js.Subscriber.next (http://localhost:9876/_karma_webpack_/webpack:/C:/Workspace/datawens-master/node_modules/rxjs/_esm5/Subscriber.js:92:1)
    at ScalarObservable.webpackJsonp.../../../../rxjs/_esm5/observable/ScalarObservable.js.ScalarObservable._subscribe (http://localhost:9876/_karma_webpack_/webpack:/C:/Workspace/datawens-master/node_modules/rxjs/_esm5/observable/ScalarObservable.js:51:1)
    at ScalarObservable.webpackJsonp.../../../../rxjs/_esm5/Observable.js.Observable._trySubscribe (http://localhost:9876/_karma_webpack_/webpack:/C:/Workspace/datawens-master/node_modules/rxjs/_esm5/Observable.js:172:1)
    at ScalarObservable.webpackJsonp.../../../../rxjs/_esm5/Observable.js.Observable.subscribe (http://localhost:9876/_karma_webpack_/webpack:/C:/Workspace/datawens-master/node_modules/rxjs/_esm5/Observable.js:160:1)
    at MergeMapOperator.webpackJsonp.../../../../rxjs/_esm5/operators/mergeMap.js.MergeMapOperator.call (http://localhost:9876/_karma_webpack_/webpack:/C:/Workspace/datawens-master/node_modules/rxjs/_esm5/operators/mergeMap.js:92:1)
    at Observable.webpackJsonp.../../../../rxjs/_esm5/Observable.js.Observable.subscribe (http://localhost:9876/_karma_webpack_/webpack:/C:/Workspace/datawens-master/node_modules/rxjs/_esm5/Observable.js:157:1)
    at FilterOperator.webpackJsonp.../../../../rxjs/_esm5/operators/filter.js.FilterOperator.call (http://localhost:9876/_karma_webpack_/webpack:/C:/Workspace/datawens-master/node_modules/rxjs/_esm5/operators/filter.js:61:1)
4

4 回答 4

4

我能够通过在我的 app.module.ts 中进行以下更改来解决此问题。希望这可以帮助。

import { HttpClient } from '@angular/common/http';
import { HttpClientModule } from '@angular/common/http';
...
...

@NgModule({
  declarations: [
    MyApp,
    HomePage,
    CameraPage,
  ],
  imports: [
    BrowserModule,
//  HttpClient,
   HttpClientModule,

于 2018-03-14T22:04:41.310 回答
4

我在尝试将测试转换为 use 时遇到了这个问题HttpTestingController这个答案只是抑制了问题并将其打印到控制台。对于下面的解决方案,我仍然有很多不明白的地方,但希望它可以帮助某人。

我的应用程序中的问题是我HttpHandler在我的providers列表中提供。这导致_this.handler在堆栈跟踪中HttpHandler的违规行中出现。http.js

var /** @type {?} */ events$ = concatMap.call(of(req), function (req) { return _this.handler.handle(req); });

HttpHandler从我的提供者中删除TestBed.configureTestModule,然后_this.handler是具有HttpInterceptorHandler适当handle功能的提供者。

于 2018-08-16T21:15:54.120 回答
2

似乎没有错误处理的订阅会导致这种情况,如此所述。该链接中的答案提供了以下示例:

user_login() {
this.userService.login(credentials).subscribe((res) => {
console.log(res);
}, (error) => {
console.log(error);
});
于 2018-05-15T15:05:48.257 回答
-1

服务调用失败类型错误 this.handler.handle 不是函数或

typeerror:此处理程序句柄不是函数

正如比尔所说,我从提供者列表中删除了 HttpClient 和 HttpHandler 并添加了 httpclientmodule 问题将解决

于 2020-05-21T22:28:00.147 回答