Last active
May 18, 2017 17:47
-
-
Save dherges/f705db03e4b4e1a8634dcfc38b72e93f to your computer and use it in GitHub Desktop.
Angular Testing Snippets: Services over HTTP
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 { Injector } from '@angular/core'; | |
| import { async, inject, TestBed } from '@angular/core/testing'; | |
| import { Http, HttpModule, Request, RequestMethod, RequestOptions, Response, | |
| ResponseOptions, URLSearchParams, XHRBackend } from '@angular/http'; | |
| import { MockBackend, MockConnection } from '@angular/http/testing'; | |
| describe('FeatureService', () => { | |
| let backend: MockBackend; | |
| //setup | |
| beforeEach(() => { | |
| TestBed.configureTestingModule({ | |
| imports: [ HttpModule ], | |
| providers: [ | |
| { provide: MockBackend, useClass: MockBackend }, | |
| { provide: XHRBackend, useExisting: MockBackend }, | |
| FeatureService | |
| ] | |
| }); | |
| backend = TestBed.get(MockBackend); | |
| spyOn(Http.prototype, 'request').and.callThrough(); | |
| }); | |
| afterEach(() => backend.verifyNoPendingRequests()); | |
| )}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment