import { | |
it, | |
inject, | |
describe, | |
beforeEach, | |
beforeEachProviders, | |
expect, | |
} from '@angular/core/testing'; | |
import { BaseRequestOptions, Response, ResponseOptions, Http } from '@angular/http'; | |
import { MockBackend, MockConnection } from '@angular/http/testing'; | |
import { AccountService, VoodooMagicService } from './../../source/scripts/services/account.service'; | |
import { provide } from '@angular/core'; | |
class StubVoodooService { | |
public augmentXhrBuild() { | |
return {}; | |
} | |
} | |
describe('AccountService', () => { | |
let service; | |
let voodoo; | |
beforeEachProviders(() => [ | |
AccountService, | |
BaseRequestOptions, | |
MockBackend, | |
provide(Http, { | |
deps: [MockBackend, BaseRequestOptions], | |
useFactory: (backend: MockBackend, defaultOptions: BaseRequestOptions) => { | |
return new Http(backend, defaultOptions); | |
}, | |
}), | |
provide(VoodooMagicService, { useClass: StubVoodooService }) | |
]); | |
beforeEach(inject([AccountService, MockBackend, VoodooMagicService], | |
(s: AccountService, backend: MockBackend, v: VoodooMagicService) => { | |
service = s; | |
voodoo = v; | |
const baseResponse = new Response(new ResponseOptions({ body: 'got response' })); | |
backend.connections.subscribe((c: MockConnection) => c.mockRespond(baseResponse)); | |
})); | |
it('should return mocked response', () => { | |
service.getUsers().subscribe((res: Response) => { | |
expect(res.text()).toBe('got responsez'); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment