I have problems with the following source code and the corresponding Unit-Test:
Source:
public laufeVorwaertsUndZurueck(laenge:number):ng.IPromise<any>{
return this.ev3DifferentialPilotAdapterService.run(laenge)
.then((response:any)=> {
return this.ev3DifferentialPilotAdapterService.rotate(180);
})
.then((response:any)=> {
return this.ev3DifferentialPilotAdapterService.run(laenge);
})
.then((response:any)=> {
return this.ev3DifferentialPilotAdapterService.rotate(180);
});
console.log("done");
}
Unit Test:
it("laufe 60cm vorwärts und laufe wieder zurück", () =>{
var promise = qService.resolve("resolved");
console.log(promise);
spyOn(ev3DifferentialPilotAdapterService, "run").and.returnValue(promise);
spyOn(ev3DifferentialPilotAdapterService, "rotate").and.returnValue(promise);
baseBallAktionenService.laufeVorwaertsUndZurueck(60);
expect(ev3DifferentialPilotAdapterService.run).toHaveBeenCalledWith(60);
expect(ev3DifferentialPilotAdapterService.run).toHaveBeenCalledTimes(2);
expect(ev3DifferentialPilotAdapterService.rotate).toHaveBeenCalledWith(180);
expect(ev3DifferentialPilotAdapterService.rotate).toHaveBeenCalledTimes(2);
})
Even tough I pass in a resolved promise object, the Callback-Functions inside the .then method are never called. The Source is fine when run normally, but behaves wrong when executed inside a Unit-test using jasmine's spyOn.
Aucun commentaire:
Enregistrer un commentaire