![](/img/trans.png)
[英]403 RXJS error when trying to subscribe to websocket | Angular
[英]Weird RxJS error when trying to use Angular TestBed
我正在嘗試在Angular項目中實施單元測試,但是遇到了錯誤消息,而且我不知道如何處理。
這是我的測試文件的代碼:
import {AuthComponent} from './auth.component';
import {ConditionalMerchandising} from '../../common/merchandising/conditionalmerchandising.service';
import {TestBed} from '@angular/core/testing';
import {RouterTestingModule} from '@angular/router/testing';
import {of} from 'rxjs';
describe('Auth base page', () => {
let _cm: jasmine.SpyObj<ConditionalMerchandising>;
beforeEach(() => {
_cm = jasmine.createSpyObj('ConditionalMerchandising', [ 'getMerchandising' ]);
TestBed.configureTestingModule({
declarations: [ AuthComponent ],
providers: [ {provide: ConditionalMerchandising, useValue: _cm } ],
imports: [ RouterTestingModule ]
}).compileComponents();
});
it ('loads the picture', () => {
TestBed.get(ConditionalMerchandising).getMerchandising.and.returnValue(of(''));
const fixture = TestBed.createComponent(AuthComponent);
fixture.detectChanges();
console.log(fixture.nativeElement.querySelector('.page-contents'));
});
});
當我運行它時,我得到一個奇怪的錯誤:
ERROR in src/app/web-ui/auth/auth.component.ts(24,17): error TS2345: Argument of type 'import("C:/Users/Bart/workspace/epicuro-web/node_modules/rxjs/internal/types").OperatorFunction<any, any>' is not assignable to parameter of type 'import("C:/Users/Bart/workspace/epicuro-web/src/app/common/node_modules/rxjs/internal/types").OperatorFunction<any, any>'.
Types of parameters 'source' and 'source' are incompatible.
Type 'import("C:/Users/Bart/workspace/epicuro-web/src/app/common/node_modules/rxjs/internal/Observable").Observable<any>' is not assignable to type 'import("C:/Users/Bart/workspace/epicuro-web/node_modules/rxjs/internal/Observable").Observable<any>'.
Types of property 'operator' are incompatible.
Type 'import("C:/Users/Bart/workspace/epicuro-web/src/app/common/node_modules/rxjs/internal/Operator").Operator<any, any>' is not assignable to type 'import("C:/Users/Bart/workspace/epicuro-web/node_modules/rxjs/internal/Operator").Operator<any, any>'.
Types of property 'call' are incompatible.
Type '(subscriber: import("C:/Users/Bart/workspace/epicuro-web/src/app/common/node_modules/rxjs/internal/Subscriber").Subscriber<any>, source: any) => import("C:/Users/Bart/workspace/epicuro-web/src/app/common/node_modules/rxjs/internal/types").TeardownLogic' is not assignable to type '(subscriber: import("C:/Users/Bart/workspace/epicuro-web/node_modules/rxjs/internal/Subscriber").Subscriber<any>, source: any) => import("C:/Users/Bart/workspace/epicuro-web/node_modules/rxjs/internal/types").TeardownLogic'.
Types of parameters 'subscriber' and 'subscriber' are incompatible.
Property '_parentOrParents' is missing in type 'Subscriber<any>' but required in type 'Subscriber<any>'.
它抱怨的那一行是const fixture = TestBed.createComponent(AuthComponent);
我在這里做錯什么事?
看起來像可觀察到的返回值的類型不匹配。 試試這個:
TestBed.get(ConditionalMerchandising).getMerchandising.and.returnValue(of({}));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.