I am trying to unit test a function that is subscribed to an observable service. Not sure where to start.
Component function I am trying to unit test:
register() {
this._registrationService.registerUser(this.form.value)
.subscribe(data => {
if (data) {
this.errorMessage = '';
this.successMessage = 'Account successfully created';
} else {
this.errorMessage = 'Error';
this.successMessage = '';
}
},
error => {
this.errorMessage = error;
this.successMessage = '';
});
}
Service:
registerUser(user) {
const registerUrl = this.apiUrl;
return this._http.post(registerUrl, JSON.stringify(user), { headers: this.apiHeaders })
.map(res => res.json())
.catch(this._handleError);
}
Aucun commentaire:
Enregistrer un commentaire