我有一個將HttpClient服務作為值的服務,我想監視post那個類的方法,所以我創建了一個看起來像這樣的間諜:spyOn(httpClient, 'post').and.returnValue(() => new Subject<any>().asObservable());但是,我收到以下錯誤:Argument of type '() => Observable<any>' is not assignable to parameter of type 'Observable<unknown>'. Type '() => Observable<any>' is missing the following properties from type 'Observable<unknown>': _isScalar, source, operator, lift, and 6 more.這是它來自的規范:describe('GraphQLClientService', () => { let service: GraphQLClientService; let httpClient: HttpClient; let postSpy: any; beforeEach(() => { httpClient = jasmine.createSpyObj('HttpClient', []); postSpy = spyOn(httpClient, 'post').and.returnValue(() => new Subject<any>().asObservable()); service = new GraphQLClientService(httpClient); });});
為 HttpClient 帖子創建間諜會創建返回值錯誤
夢里花落0921
2023-02-24 10:41:03