dojo/tests/unit/throttle.js

Maintainability

80.48

Lines of code

52

Created with Raphaël 2.1.002550751002015-5-18

2015-5-18
Maintainability: 80.48

Created with Raphaël 2.1.00153045602015-5-18

2015-5-18
Lines of Code: 52

Difficulty

13.35

Estimated Errors

0.28

Function weight

By Complexity

Created with Raphaël 2.1.0<anonymous>1

By SLOC

Created with Raphaël 2.1.0<anonymous>47
1
define([
2
    'intern!object',
3
    'intern/chai!assert',
4
    '../../throttle',
5
    'sinon'
6
], function (registerSuite, assert, throttle, sinon) {
7
    registerSuite({
8
        name: 'dojo/throttle',
9
 
10
        sync: function () {
11
            var spy = sinon.spy();
12
            var throttler = sinon.spy(throttle(spy, 100));
13
 
14
            throttler();
15
            throttler();
16
            throttler();
17
 
18
            setTimeout(this.async().callback(function () {
19
                assert.ok(spy.callCount < throttler.callCount);
20
            }), 1000);
21
        },
22
 
23
        async: function () {
24
            var spy = sinon.spy();
25
            var throttler = sinon.spy(throttle(spy, 100));
26
 
27
            throttler();
28
            setTimeout(function () {
29
                throttler();
30
            }, 40);
31
            setTimeout(function () {
32
                throttler();
33
            }, 80);
34
            setTimeout(function () {
35
                throttler();
36
            }, 120);
37
            setTimeout(function () {
38
                throttler();
39
            }, 180);
40
            setTimeout(function () {
41
                throttler();
42
            }, 220);
43
            setTimeout(function () {
44
                throttler();
45
            }, 350);
46
 
47
            setTimeout(this.async().callback(function () {
48
                assert.ok(spy.callCount < throttler.callCount);
49
            }), 2000);
50
        }
51
    });
52
});