Skip to content

Commit

Permalink
Expand pureComputed spectate test to show why the version needs to be…
Browse files Browse the repository at this point in the history
… updated before the spectate event.
  • Loading branch information
mbest committed Dec 14, 2016
1 parent 4296eed commit 4e55d4b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion spec/pureComputedBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,25 @@ describe('Pure Computed', function() {

it('Should notify "spectator" subscribers whenever the value changes', function () {
var observable = new ko.observable('A');
var computed = ko.pureComputed(function () { return observable(); });
var computed = ko.pureComputed(observable);
var computed2 = ko.pureComputed(computed);
var notifiedValues = [];
computed.subscribe(function (value) {
notifiedValues.push(value);
expect(computed()).toBe(value);
expect(computed2()).toBe(value);
}, null, "spectate");

expect(notifiedValues).toEqual([]);

// Reading the computed for the first time causes a notification
expect(computed()).toEqual('A');
expect(computed2()).toEqual('A');
expect(notifiedValues).toEqual(['A']);

// Reading it a second time doesn't
expect(computed()).toEqual('A');
expect(computed2()).toEqual('A');
expect(notifiedValues).toEqual(['A']);

// Changing the dependency doesn't, but reading the computed again does
Expand Down

0 comments on commit 4e55d4b

Please sign in to comment.