summaryrefslogtreecommitdiffstats
path: root/test/fastdom-strict-test.js
blob: 688e8b271b6367b91145413c464e764c0726c087 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*global suite, setup, suiteSetup, suiteTeardown, teardown, test, assert, fastdomPromised*/
/*jshint maxlen:false*/

suite('fastdom-strict', function() {
  var fastdom;
  var el;

  suiteSetup(function(done) {
    var script = document.createElement('script');
    script.src = '/base/fastdom-strict.js';
    document.head.appendChild(script);
    script.onload = function() {
      fastdom = window.fastdom.extend(fastdomPromised);
      done();
    };
  });

  suiteTeardown(function() {
    fastdom.strict(false);
  });

  setup(function() {
    return fastdom.mutate(function() {
      el = document.createElement('div');
      el.style.height = '100px';
      el.style.width = '100px';
      document.body.appendChild(el);
    });
  });

  teardown(function() {
    return fastdom.mutate(function() {
      el.remove();
    });
  });

  test('measuring throws outside of fastdom', function() {
    assert.throws(function() {
      return el.clientWidth;
    });
  });

  test('measuring does not throws inside `fastdom.measure()`', function() {
    return fastdom.measure(function() {
      return el.clientWidth;
    });
  });

  test('mutating throws outside of fastdom', function() {
    assert.throws(function() {
      el.innerHTML = 'foo';
    });
  });

  test('mutating does not throws inside `fastdom.mutate()`', function() {
    return fastdom.mutate(function() {
      el.innerHTML = 'foo';
    });
  });

  test('it can be disabled and enabled', function(done) {
    fastdom.strict(false);

    assert.doesNotThrow(function() {
      return el.clientWidth;
    });

    fastdom.strict(true);

    assert.throws(function() {
      return el.clientWidth;
    });

    fastdom.measure(function() {
      el.clientWidth;
    }).then(done);
  });
});