There is a good library that provides syntax sugar for Promise validations via Jasmine jasmine-promise-matchers. It comes hard to test complex result objects, example proposes to use jasmine.objectContaining from jasmine-matchers,
but the easier way for the same is just to map promise into tested value and use toBeResolvedWith on a projection from pormise.
This file contains 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
var result = service | |
.calMethodReturnsPromise() | |
.then(function(data) { | |
return data.timeSlots[0].parts[0].slots[0].title; // Map result into smaller projection | |
}); | |
$httpBackend.flush(); | |
expect(result).toBePromise(); | |
expect(result).toBeResolved(); | |
expect(result).toBeResolvedWith(expectedState); |
No comments:
Post a Comment