diff options
Diffstat (limited to 'test/fastdom-promised-test.js')
-rw-r--r-- | test/fastdom-promised-test.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/fastdom-promised-test.js b/test/fastdom-promised-test.js new file mode 100644 index 0000000..959800e --- /dev/null +++ b/test/fastdom-promised-test.js @@ -0,0 +1,48 @@ +/*global suite, setup, test, assert, sinon, fastdomPromised*/ +/*jshint maxlen:false*/ + +suite('fastdom-promised', function() { + var fastdom; + + setup(function() { + fastdom = window.fastdom.extend(fastdomPromised); + }); + + test('it returns a Promise that resolves after the task is run', function(done) { + var spy = sinon.spy(); + + fastdom.measure(spy) + .then(function() { + sinon.assert.calledOnce(spy); + done(); + }); + }); + + test('promises can be returned from tasks', function() { + var spy1 = sinon.spy(); + var spy2 = sinon.spy(); + + return fastdom.measure(function() { + spy1(); + return fastdom.mutate(spy2); + }) + + .then(function() { + sinon.assert.calledOnce(spy1); + sinon.assert.calledOnce(spy2); + assert.isTrue(spy1.calledBefore(spy2)); + }); + }); + + test('calling `fastdom.clear(promise)` works', function(done) { + var spy = sinon.spy(); + var task = fastdom.measure(spy); + + fastdom.clear(task); + + requestAnimationFrame(function() { + sinon.assert.notCalled(spy); + done(); + }); + }); +}); |