Angular 2. My component contains the following piece of code:

export class SectorComponent implements OnInit {

let myList = [];
let loading = false;

refresh(){
this.loading = true;
const that : any = this;
this.dataService.products().subscribe(products=>{
    
that.myList= products;
console.log(that.myList);
that.loading = false;
});


}

}



the refresh() method is called from a button. Now I want to unit test it. 
the dataService is mocked to return a set of products. In my test, I want 
to see the corre

  it("should get products", () => {
    component.refresh();
    console.log('total found', component.myList.length)
    expect(component.myList.length).toEqual(1);
  });




the test fails because myList is always 1 while console.log(that.myList) 
returns 1. I am almost sure it is related to the expect() happening before 
observable is complete. How do I go handle it please?

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/angular/db072747-9124-430b-8fde-2d3ff30502fd%40googlegroups.com.

Reply via email to