summaryrefslogtreecommitdiffstats
path: root/test/fastdom-promised-test.js
blob: 959800e30d31cab5ed0cc41705502ee53acb8a32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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();
    });
  });
});