Skip to content

Commit

Permalink
Add spec from 3.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mbest committed Mar 24, 2017
1 parent a73cee4 commit 5f0b9a7
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions spec/asyncBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1177,5 +1177,36 @@ describe('Deferred', function() {

jasmine.Clock.tick(1);
});

it('Should not cause loss of updates when an intermediate value is read by a dependent computed observable', function() {
// From https://github.com/knockout/knockout/issues/1835
var one = ko.observable(false).extend({deferred: true}),
onePointOne = ko.computed(one).extend({deferred: true}),
two = ko.observable(false),
three = ko.computed(function() { return onePointOne() || two(); }),
threeNotifications = [];

three.subscribe(function(val) {
threeNotifications.push(val);
});

// The loop shows that the same steps work continuously
for (var i = 0; i < 3; i++) {
expect(onePointOne() || two() || three()).toEqual(false);
threeNotifications = [];

one(true);
expect(threeNotifications).toEqual([]);
two(true);
expect(threeNotifications).toEqual([true]);
two(false);
expect(threeNotifications).toEqual([true]);
one(false);
expect(threeNotifications).toEqual([true]);

jasmine.Clock.tick(1);
expect(threeNotifications).toEqual([true, false]);
}
});
});
});

0 comments on commit 5f0b9a7

Please sign in to comment.