Skip to content

Instantly share code, notes, and snippets.

@dherges
Last active May 18, 2017 17:47
Show Gist options
  • Select an option

  • Save dherges/f705db03e4b4e1a8634dcfc38b72e93f to your computer and use it in GitHub Desktop.

Select an option

Save dherges/f705db03e4b4e1a8634dcfc38b72e93f to your computer and use it in GitHub Desktop.
Angular Testing Snippets: Services over HTTP
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