diff --git a/src/observe.js b/src/observe.js index 9c00bee..999cbec 100644 --- a/src/observe.js +++ b/src/observe.js @@ -503,6 +503,8 @@ observer.check_(); } + + scheduleReset(); } var record = { diff --git a/tests/test.js b/tests/test.js index 4361f29..2ff8267 100644 --- a/tests/test.js +++ b/tests/test.js @@ -18,6 +18,19 @@ var callbackInvoked = false; window.testingExposeCycleCount = true; +function then(fn) { + setTimeout(function() { + Platform.performMicrotaskCheckpoint(); + fn(); + }, 0); + + return { + then: function(next) { + return then(next); + } + }; +} + function noop() {} function callback() { @@ -38,8 +51,9 @@ function assertNoChanges() { assert.isUndefined(callbackArgs); } -function assertPathChanges(expectNewValue, expectOldValue) { - observer.deliver(); +function assertPathChanges(expectNewValue, expectOldValue, dontDeliver) { + if (!dontDeliver) + observer.deliver(); assert.isTrue(callbackInvoked); @@ -48,8 +62,10 @@ function assertPathChanges(expectNewValue, expectOldValue) { assert.deepEqual(expectNewValue, newValue); assert.deepEqual(expectOldValue, oldValue); - assert.isTrue(window.dirtyCheckCycleCount === undefined || - window.dirtyCheckCycleCount === 1); + if (!dontDeliver) { + assert.isTrue(window.dirtyCheckCycleCount === undefined || + window.dirtyCheckCycleCount === 1); + } callbackArgs = undefined; callbackInvoked = false; @@ -604,6 +620,25 @@ suite('PathObserver Tests', function() { observer.close(); }); + test('Path - root is initially null', function(done) { + var model = { }; + + var path = Path.get('foo'); + observer = new PathObserver(model, 'foo.bar'); + observer.open(callback); + + model.foo = { }; + then(function() { + model.foo.bar = 1; + + }).then(function() { + assertPathChanges(1, undefined, true); + + observer.close(); + done(); + }); + }); + test('Path With Indices', function() { var model = [];