Error: <spyOn> : handleError() method does not exist
单元测试出错:
Error: : handleError() method does not exist
Usage: spyOn(, )
at
at UserContext.apply (http://localhost:9876/karma_webpack/src/global-message/http-interceptors/http-error.interceptor.spec.ts:121:9)
at ZoneDelegate.invoke (http://localhost:9876/karma_webpack/C:/Code/SPA/spartacus/node_modules/zone.js/dist/zone.js:386:30)
at ProxyZoneSpec.onInvoke (http://localhost:9876/karma_webpack/C:/Code/SPA/spartacus/node_modules/zone.js/dist/zone-testing.js:292:43)
at ZoneDelegate.invoke (http://localhost:9876/karma_webpack/C:/Code/SPA/spartacus/node_modules/zone.js/dist/zone.js:385:36)
at Zone.run (http://localhost:9876/karma_webpack/C:/Code/SPA/spartacus/node_modules/zone.js/dist/zone.js:143:47)
at runInTestZone (http://localhost:9876/karma_webpack/C:/Code/SPA/spartacus/node_modules/zone.js/dist/zone-testing.js:545:38)
at UserContext. (http://localhost:9876/karma_webpack/C:/Code/SPA/spartacus/node_modules/zone.js/dist/zone-testing.js:560:24)
原因出在下图高亮的这行代码上:
handlerClass的类型是一个function,而不是具体的对象实例。因此,handler.handleError为undefined:
实际上,一个function可用的属性有且仅有下列几种:
使用下列代码后错误消失:
const handler = TestBed.inject(handlerClass) as HttpErrorHandler;
更多Jerry的原创文章,尽在:“汪子熙”:
相关文章
- 解决php编译报错configure: error: mcrypt.h not found. Please reinstall libmcrypt.
- ERROR OGG-00199 Table t3.T3_TAB does not exist in target database.
- ERROR 2003 (HY000): Can't connect to MySQL server
- Error: Object INSTANCES_UTIL does not exist
- C# "error CS1729: 'XXClass' does not contain a constructor that takes 0 arguments"的解决方案
- error: style attribute '@android:attr/windowEnterAnimation' not found.
- Communication error with the external tax system VERTEX
- workaround for error message "Table maintenance not allowed for table XXX"
- 如何解决创建Account时的error message BP category 2 does not fit the data in category 1
- Fix error message: maven error: package org.junit does not exist
- SAP UI5应用在SAP WebIDE里clone之后出现404 not found error for sap-ui-core.js错误的原因分析
- uniapp微信小程序开发者工具-真机调试报错:message:Error: /XXX.bak.js does not exists
- An error occurred Field [id] referenced by index [] does not exist.
- Android的报错提示:Error:Cause: buildToolsVersion is not specified.
- 成功解决ERROR: Could not build wheels for bottleneck, which is required to install pyproject.toml-based
- wscript:329: error: Could not autodetect OpenSSL support. Make sure OpenSSL development packages are
- 成功解决ERROR: Could not find a version that satisfies the requirement xgboost (from versions: none) ERR
- 成功解决ERROR: Could not install packages due to an EnvironmentError: [WinError 5] 拒绝访问。backend_agg.cp36
- 已解决ERROR: Could not find a version that satisfies the requirement COMMON_SAFE_ASCII_CHARACTERS (from
- Mariadb: error Relay log read failure: Could not parse relay log event entry
- pip install matplot lib安装报错ERROR: Could not install packages due to an EnvironmentError: [WinError 5
- 成功解决ERROR: Could not install packages due to an EnvironmentError: [Errno 28] No space left on device
- Error running ‘Tomcat‘: Unable to open debugger port (127.0.0.1:2148): java.net.SocketExceptio