Skip to content

Instantly share code, notes, and snippets.

@mraible
Created March 16, 2016 05:18
Show Gist options
  • Save mraible/573c892bbd9d4d799dbd to your computer and use it in GitHub Desktop.
Save mraible/573c892bbd9d4d799dbd to your computer and use it in GitHub Desktop.
Correct Search Service
import {provide} from 'angular2/core';
import {SpyObject} from 'angular2/testing_internal';
import {SearchService} from '../search.service';
export class MockSearchService extends SpyObject {
getAllSpy;
getByIdSpy;
searchSpy;
saveSpy;
fakeResponse;
constructor() {
super(SearchService);
this.fakeResponse = null;
this.getAllSpy = this.spy('getAll').andReturn(this);
this.getByIdSpy = this.spy('get').andReturn(this);
this.searchSpy = this.spy('search').andReturn(this);
this.saveSpy = this.spy('save').andReturn(this);
}
subscribe(callback) {
callback(this.fakeResponse);
}
setResponse(json: any): void {
this.fakeResponse = json;
}
getProviders(): Array<any> {
return [provide(SearchService, {useValue: this})];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment