Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save dherges/eebe77123ead2fbf5594fe947045a652 to your computer and use it in GitHub Desktop.
Angular Testing Snippets: Services over HTTP
/** This class implements some features that should be tested. */
@Injectable()
export class FeatureService {
constructor(
private http: Http
) {}
login(user: string, password: string): Observable<boolean> {
let body = new URLSearchParams();
body.set(`user`, user);
body.set(`password`, password);
let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
return this.http.post(`auth/login`, body, { headers })
.map((res: Response) => res.ok)
.catch((err) => Observable.of(false));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment