【发布时间】:2023-03-13 02:43:01
【问题描述】:
您好,我在 ngonit 中添加了这段代码,用于轮询,添加后我的所有测试用例都失败了。请帮忙解决一下?
ngOnInit(): void {
this.timeInterval = interval(5000)
.pipe(
startWith(0),
switchMap(() => this.deviceService.getDeviceList())
)
.pipe(
takeUntil(this.deviceService.flag$),
repeatWhen(() => this.deviceService.flag$)
)
.subscribe((success: any) => {
this.gridApi?.setRowData(this.updatedData);
console.log("hello")
this.updatedData = success;
}, retry(2));
这是完全错误
HeadlessChrome 88.0.4324 (Windows 10.0.0) DeviceComponent testing columnresize of the grid for other scenario FAILED
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/_esm2015/internal/util/subscribeTo.js:27:1)
at innerSubscribe (http://localhost:9876/_karma_webpack_/node_modules/rxjs/_esm2015/internal/innerSubscribe.js:69:23)
at TakeUntilOperator.call (http://localhost:9876/_karma_webpack_/node_modules/rxjs/_esm2015/internal/operators/takeUntil.js:11:52)
at Observable.subscribe (http://localhost:9876/_karma_webpack_/node_modules/rxjs/_esm2015/internal/Observable.js:23:1)
at RepeatWhenOperator.call (http://localhost:9876/_karma_webpack_/node_modules/rxjs/_esm2015/internal/operators/repeatWhen.js:11:1)
at Observable.subscribe (http://localhost:9876/_karma_webpack_/node_modules/rxjs/_esm2015/internal/Observable.js:23:1)
at DeviceComponent.ngOnInit (http://localhost:9876/_karma_webpack_/src/app/device/device.component.ts:99:4)
at callHook (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:3937:1)
at callHooks (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:3901:1)
at executeInitAndCheckHooks (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:3842:1)
Failed: Cannot read property 'unsubscribe' of undefined
at <Jasmine>
at DeviceComponent.ngOnDestroy (http://localhost:9876/_karma_webpack_/main.js:28373:23)
at UserContext.<anonymous> (http://localhost:9876/_karma_webpack_/src/app/device/device.component.spec.ts:196:15)
at ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:365:1)
at AsyncTestZoneSpec.onInvoke (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-testing.js:763:1)
at ProxyZoneSpec.onInvoke (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-testing.js:302:1)
at ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:364:1)
at Zone.runGuarded (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:134:1)
at runInTestZone (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-testing.js:885:1)
at UserContext.<anonymous> (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-testing.js:823:1)
at ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:365:1)
HeadlessChrome 88.0.4324 (Windows 10.0.0):执行 1 of 385 (1 FAILED) (0 secs / 1.732 secs) HeadlessChrome 88.0.4324 (Windows 10.0.0) DeviceComponent testing columnresize of the grid for other scenario FAILED TypeError:您在预期流的位置提供了“未定义”。您可以提供 Observable、Promise、Array 或 Iterable。 在 在 subscribeTo (http://localhost:9876/karma_webpack/node_modules/rxjs/_esm2015/internal/util/subscribeTo.js:27:1) 在innerSubscribe (http://localhost:9876/karma_webpack/node_modules/rxjs/_esm2015/internal/innerSubscribe.js:69:23) 在 TakeUntilOperator.call (http://localhost:9876/karma_webpack/node_modules/rxjs/_esm2015/internal/operators/takeUntil.js:11:52) 在 Observable.subscribe (http://localhost:9876/karma_webpack/node_modules/rxjs/_esm2015/internal/Observable.js:23:1) 在 RepeatWhenOperator.call (http://localhost:9876/karma_webpack/node_modules/rxjs/_esm2015/internal/operators/repeatWhen.js:11:1) 在 Observable.subscribe (http://localhost:9876/karma_webpack/node_modules/rxjs/_esm2015/internal/Observable.js:23:1) 在 DeviceComponent.ngOnInit (http://localhost:9876/karma_webpack/src/app/device/device.component.ts:99:4) 在 callHook (http://localhost:9876/karma_webpack/node_modules/@angular/core/ivy_ngcc/fesm2015/core.js:3937:1) 在 callHooks (http://localhost:9876/karma_webpack/node_modules/@angular/core/ivy_ngcc/fesm2015/core.js:3901:1) 在 executeInitAndCheckHooks (http://localhost:9876/karma_webpack/node_modules/@angular/core/ivy_ngcc/fesm2015/core.js:3842:1) 失败:无法读取未定义的属性“取消订阅” 在 在 DeviceComponent.ngOnDestroy (http://localhost:9876/karma_webpack/main.js:28373:23) 在用户上下文。 (http://localhost:9876/karma_webpack/src/app/device/device.component.spec.ts:196:15) 在 ZoneDelegate.invoke (http://localhost:9876/karma_webpack/node_modules/zone.js/dist/zone-evergreen.js:365:1)
【问题讨论】:
标签: angular unit-testing jasmine karma-jasmine