Angular 角度测试-可观察管道不是一项功能

Angular 角度测试-可观察管道不是一项功能,angular,jasmine,rxjs,karma-jasmine,angular-test,Angular,Jasmine,Rxjs,Karma Jasmine,Angular Test,我想为照片上传方法编写一个单元测试。但是我得到的失败了:this.task.snapshotChanges(…)。管道不是函数 TypeError:this.task.Snapshot更改(…)。管道不是函数错误为了简化这个问题,我将代码全部放在一个方法中: 组成部分 组件规范 it('should upload file',异步(()=>{ const supportedFile=新文件([''],'filename.png',{type:'image/',lastModified:2233}

我想为照片上传方法编写一个单元测试。但是我得到的
失败了:this.task.snapshotChanges(…)。管道不是函数
TypeError:this.task.Snapshot更改(…)。管道不是函数
错误

为了简化这个问题,我将代码全部放在一个方法中:

组成部分 组件规范
it('should upload file',异步(()=>{
const supportedFile=新文件([''],'filename.png',{type:'image/',lastModified:2233});
常量文件列表={
项目:()=>{
返回支持的文件;
}
};
const spy=(serviceStub.uploadPhoto)和.returnValue({
百分比变化:()=>of(null),
快照更改:()=>{
返回{
getDownloadURL(){
返回(空);
}
};
}
});
组件启动加载(文件列表);
expect(spy).toHaveBeenCalledWith(`users/${component.uid}',supportedFile);
}));

单元测试的解决方案是添加以下行:
(service.getFileReference).和.returnValue({
getDownloadURL:()=>of(null)

});

据我了解,出现此错误是因为
此.task.snapshotChanges(…)
在spy中返回一个
对象。
相反,它应该返回一个
可观察的

const spy = (<jasmine.Spy>serviceStub.uploadPhoto).and.returnValue({
  percentageChanges: () => of(null),
  snapshotChanges: () => {
    return of({
      getDownloadURL() {
        return of(null);
      }
    })
  }
constspy=(serviceStub.uploadPhoto)和.returnValue({
百分比变化:()=>of(null),
快照更改:()=>{
归还({
getDownloadURL(){
返回(空);
}
})
}
}))


另外,
getDownloadURL:()=>of(null)
也应该返回Observable。

发布
快照更改
方法我实际上不能^^。它来自angular firebase提供的第三方库。但是它返回一个
可观察的
。这是什么版本的RxJS?@Nick RxJS:6.0.0 angularfire版本是什么
  it('should upload file', async(() => {
    const supportedFile = new File([''], 'filename.png', {type: 'image/', lastModified: 2233});
    const fileList = {
      item: () => {
        return supportedFile;
      }
    };
    const spy = (<jasmine.Spy>serviceStub.uploadPhoto).and.returnValue({
      percentageChanges: () => of(null),
      snapshotChanges: () => {
        return {
          getDownloadURL() {
            return of(null);
          }
        };
      }
    });

    component.startUpload(<any>fileList);

    expect(spy).toHaveBeenCalledWith(`users/${component.uid}`, supportedFile);
  }));
const spy = (<jasmine.Spy>serviceStub.uploadPhoto).and.returnValue({
  percentageChanges: () => of(null),
  snapshotChanges: () => {
    return of({
      getDownloadURL() {
        return of(null);
      }
    })
  }