Last active
February 8, 2016 09:05
-
-
Save clemcke/c5902028a1b0934b03d9 to your computer and use it in GitHub Desktop.
Sample spec that uses appInjector() and a service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {it, describe, expect, inject, beforeEach, beforeEachProviders} from 'angular2/testing' | |
import {PersonService, PERSON_SERVICE_PROVIDERS, personServiceLoadedPromise} from './person.service' | |
// Contents of person.service.ts | |
//@Injectable() | |
//export class PersonService { | |
// constructor(private _http: Http) { } | |
// | |
// init(): Promise<boolean>{ | |
// return this._http.get('myurl').toPromise(); | |
// } | |
//} | |
// | |
//function personServiceLoadedPromise(next, prev): Promise<boolean>{ | |
// return appInjector().get(PersonService).init(); | |
//} | |
// | |
//const PERSON_SERVICE_PROVIDERS = [ | |
// PersonService, | |
// HTTP_PROVIDERS | |
//]; | |
import {appInjector} from "./app-injector"; | |
import {Injector} from 'angular2/core' | |
describe('PersonService',()=>{ | |
describe('#personServiceLoadedPromise',()=> { | |
beforeEachProviders(()=>[PERSON_SERVICE_PROVIDERS]); | |
beforeEach(inject([PersonService],()=>{ | |
appInjector(Injector.resolveAndCreate([PERSON_SERVICE_PROVIDERS])); | |
})); | |
it('calls #init()', ()=> { | |
let service = appInjector().get(PersonService); | |
spyOn(service, 'init'); | |
personServiceLoadedPromise(null,null); | |
expect(service.init).toHaveBeenCalled(); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment