多个嵌套承诺角度2测试

时间:2017-06-19 09:47:09

标签: angular unit-testing testing promise

我有一个很大的问题,因为当我尝试测试包含多个承诺的选择主题功能时,我总是看到像

这样的错误
  当没有当前规范时使用

'expect',这可能是因为异步测试超时

我尝试使用fakeAsync,但它会抛出

  

无法在假异步测试中制作XHR。

it('should set regular topic', async(inject([FirebaseRateService], (service: FirebaseRateService) => {
      service.setTopicId("randomTopic 2");

      service.getTopicStream()
        .subscribe( (topicId:string) =>{
          console.log(topicId);
          expect(topicId).toBe("randomTopic 2");
        })
      
  })));

  setTopicId( topic_id:string ){
    if( !this.auth.check() )
      this.auth.signAnonyous().then( () => this.selectTopic(topic_id));
    else 
      this.selectTopic(topic_id);      
  }

  private selectTopic( topic_id:string ){
    selectTopic( this.db, topic_id )
      .then(
        () => {
          this.topicId = topic_id;
          this.topicStream.next(topic_id);
        }
      )
  }

  getTopicStream(){
    if(this.topicId)
      return this.topicStream.startWith(this.topicId);
    return this.topicStream.asObservable();
  }

0 个答案:

没有答案
相关问题