Last active
May 18, 2017 07:21
-
-
Save dherges/eebe77123ead2fbf5594fe947045a652 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
| /** 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