我正在尝试以角度方式运行测试,但显然出现了类似以下错误:
TypeError: _this.handler.handle is not a function
at MergeMapSubscriber.project (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/common/esm5/http.js:1464:80)
at MergeMapSubscriber.webpackJsonp../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._tryNext (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/_esm5/operators/mergeMap.js:128:1)
at MergeMapSubscriber.webpackJsonp../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapSubscriber._next (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/_esm5/operators/mergeMap.js:118:1)
at MergeMapSubscriber.webpackJsonp../node_modules/rxjs/_esm5/Subscriber.js.Subscriber.next (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/_esm5/Subscriber.js:92:1)
at ScalarObservable.webpackJsonp../node_modules/rxjs/_esm5/observable/ScalarObservable.js.ScalarObservable._subscribe (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/_esm5/observable/ScalarObservable.js:51:1)
at ScalarObservable.webpackJsonp../node_modules/rxjs/_esm5/Observable.js.Observable._trySubscribe (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/_esm5/Observable.js:172:1)
at ScalarObservable.webpackJsonp../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/_esm5/Observable.js:160:1)
at MergeMapOperator.webpackJsonp../node_modules/rxjs/_esm5/operators/mergeMap.js.MergeMapOperator.call (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/_esm5/operators/mergeMap.js:92:1)
at Observable.webpackJsonp../node_modules/rxjs/_esm5/Observable.js.Observable.subscribe (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/_esm5/Observable.js:157:1)
at FilterOperator.webpackJsonp../node_modules/rxjs/_esm5/operators/filter.js.FilterOperator.call (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/_esm5/operators/filter.js:61:1)
我没有在测试中进行任何更改,但在组件中确实添加了新的导入:import {Router} from "@angular/router";
,当然,在测试中我确实在导入中添加了RouterModule
。我该怎么办?
答案 0 :(得分:0)
问题是我没有模拟组件中使用的方法。正确模拟确实可以解决问题。
答案 1 :(得分:-1)
删除node_modules文件夹和 在命令中执行: npm install