title: Angular2 final version: Injected Service method under unit test returning undefined
body: <p>I am trying to write some unit-tests on a component that got some services injected into it, to load the data from server. Data is loaded in this component on OnInit() method. I am trying that service method returns some dummy data, using spyOn. Following is unit-test setup - </p>
  
  <pre><code>let comp: MyComponent;
  let fixture: ComponentFixture&lt;MyComponent&gt;;
  let staticDataService: any;
  let spy: jasmine.Spy;
  let allCountries: string[];
  
  describe('MyComponent', () =&gt; {
  beforeEach( async(() =&gt; {
  
      TestBed.configureTestingModule({
          imports : [ FormsModule, HttpModule ],
          declarations : [MyComponent],
          providers: [ StaticDataService ]
      })
      .compileComponents();
  }));
  
  beforeEach(() =&gt; {
      fixture = TestBed.createComponent(MyComponent);
      comp = fixture.componentInstance;
      staticDataService = fixture.debugElement.injector.get(StaticDataService);
      allCountries = [] = ["US", "UK"];
      spy = spyOn(staticDataService, 'getCountries').and.returnValue(Promise.resolve(allCountries));
      });
  it('Countries should be set', () =&gt; {
      expect(comp.allCountries).toEqual(allCountries);
      }); 
  });
  </code></pre>
  
  <p>Following is the component class that I am unit-testing - </p>
  
  <pre><code>@Component({
    moduleId: module.id,
    selector: 'myeditor',
    templateUrl: 'my.component.html',
    styleUrls: ['my.component.css']
  })
  export class MyComponent implements OnInit {
    allCountries: string[];
    constructor(private _staticDataServices: StaticDataService) {}
    ngOnInit() {
      this.getDataFromServer();
    }
  
    getDataFromServer()
    {
      this.allCountries = this._staticDataServices.getCountries();
    }
  </code></pre>
  
  <p>I am getting the following error - </p>
  
  <pre><code>    Chrome 53.0.2785 (Windows 7 0.0.0) MyComponent Countries should be set FAILED
      [1]     Expected undefined to equal [ 'US', 'UK' ].
  </code></pre>
  
  <p>Under the same unit-tests few other tests are working fine, that are not dependent on injected services. Getting 'undefined' while testing the properties that are set by services. 
  Can someone please help what I am doing wrong here?</p>
  
  <p>Thanks</p>