lundi 19 juin 2017

Multiple nested promises angular 2 tests

I have a huge problem because when i try to test my select topic function which contain a multiple promise i always seen error like

'expect' was used when there was no current spec, this could be because an asynchronous test timed out

I try to use fakeAsync but it throw

Cannot make XHRs from within a fake async test.

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();
  }

Aucun commentaire:

Enregistrer un commentaire