I’m trying to write a jasmine spec for a computed observable like below:
self.positionDate = ko.computed(function () {
var dateString = "";
var start = moment(self.positionStartDate()).format("LL");
var end = moment(self.positionEndDate()).format("LL");
if (start !== end) {
dateString = sprintf("%s - %s", start, end);
}
else {
dateString = sprintf("%s", start);
}
return dateString;
}).extend({ throttle: 1 });
With the throttle, the positionDate computed function is not getting updated. I’ve tried artificially waiting as well as calling valueHasMutated() both to no avail.
Has anyone successfully written a spec on a throttled computed?
Because of the usage of the
throttleyou made your observable “async” so you need to use the asynchronous specs features in Jasmine.So you need to use the
runsandwaitsfunctions something like:Demo JSFiddle.