Skip to content

Commit

Permalink
Workaround spurious failure in async test
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveSanderson committed Nov 20, 2012
1 parent 00b39b8 commit 0cfe3f2
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions spec/asyncBehaviors.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
describe("Throttled observables", function() {

it("Should notify subscribers asynchronously after writes stop for the specified timeout duration", function() {
var observable = ko.observable('A').extend({ throttle: 50 });
var notifiedValues = [];
observable.subscribe(function(value) {
notifiedValues.push(value);
});
var observable, notifiedValues;

// Mutate a few times
observable('B');
observable('C');
observable('D');
expect(notifiedValues.length).toEqual(0); // Should not notify synchronously
waits(10); // Was getting spurious failures (blocks running out of order, mainly on IE) if the first item queued wasn't a "wait"
runs(function() {
observable = ko.observable('A').extend({ throttle: 50 });
notifiedValues = [];
observable.subscribe(function(value) {
notifiedValues.push(value);
});

// Mutate a few times
observable('B');
observable('C');
observable('D');
expect(notifiedValues.length).toEqual(0); // Should not notify synchronously
});

// Wait
waits(20);
Expand Down

0 comments on commit 0cfe3f2

Please sign in to comment.