Friday, 27 July 2018

Testing Promise with Jasmine

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.
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);
view raw promiseTest.js hosted with ❤ by GitHub

No comments:

Post a Comment