Last active
June 17, 2016 15:30
-
-
Save aarmora/2d349455e1ed61fc588ea1e7389f4054 to your computer and use it in GitHub Desktop.
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, | |
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