问题 I have a very simple function load() that I'm trying to unit test with Jasmine. this.service.loadObject() returns a Promise. How can I test that this.logService.error will be called if the Promise is rejected ? load() { this.service.loadObject().then(x => { this.variable = x; }).catch(ex => this.logService.error(ex)); } 回答1: Something like this should work: it("should catch the error", done => { spyOn(service, "loadObject").and.returnValue(Promise.reject("test error")); spyOn(logService,