ich ein Problem bin vor während Unit-Tests meines Dienstes dies mein Testfall istKarma Rückruf ist immer undefiniert
it("updateUserProfile() should update user profile", async(() => {
mockBackend.connections.subscribe((connection: MockConnection) => {
let responseOpts = new ResponseOptions({ body: JSON.stringify({ username: "testuser" }) });
connection.mockRespond(new Response(responseOpts));
});
let obj = {
callback: (r) => {
expect(r.username).toBe("testuser");
}
};
spyOn(obj, "callback").and.callThrough();
service.updateUserProfile({}, obj.callback);
expect(obj.callback).toHaveBeenCalled();
}));
und das ist mein Service
updateUserProfile(user: Profile, callback?: Function): void {
let sub = this.http.patch(url, user, { headers: this.getHeaders() }).subscribe(r => {
callback(r);
if (sub) sub.unsubscribe();
});
}
in diesem Fall ist es funktioniert gut mein spy
ist ist wahr, dass Rückruf wurde gefeuert, aber der Code in meinem callback
ist immer undefiniert Ich möchte die Antwort auch testen.