I'm trying to write a test for a ko.computed
field that is dependent on two other complex computeds (removed here for demonstration).
function PositionsViewModel(options) {
var self = this;
self.computed1 = ko.computed(function() { return 1; });
self.computed2 = ko.computed(function() { return 2; });
self.computedIWantToTest = ko.computed(function() {
return self.computed1() + self.computed2();
});
}
In my jasmine test I create an instance of the VM in a beforeEach like so:
this.subject = new PositionsViewModel();
I want to be able to stub computed1
and computed2
so that I may test computedIWantToTest
in isolation. So far my attempts to do so have failed.
I've tried stubbing on the vm instance directly. But, it seems that, even though the methods are overwritten the computed caches the function in some way.