forked from thorst/jquery-idletimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidle-timer_test.js
64 lines (52 loc) · 1.74 KB
/
idle-timer_test.js
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
(function($) {
/*
======== A Handy Little QUnit Reference ========
http://docs.jquery.com/QUnit
Test methods:
expect(numAssertions)
stop(increment)
start(decrement)
Test assertions:
ok(value, [message])
equal(actual, expected, [message])
notEqual(actual, expected, [message])
deepEqual(actual, expected, [message])
notDeepEqual(actual, expected, [message])
strictEqual(actual, expected, [message])
notStrictEqual(actual, expected, [message])
raises(block, [expected], [message])
*/
module("jQuery#idle-timer");
asyncTest( "default behavior", function() {
expect( 1 );
$( document ).on( "idle.idleTimer", function(){
ok( true, "idleTimer fires at document by default" );
$.idleTimer( "destroy" );
start();
});
$.idleTimer( 100 );
});
$.each( ["mousemove", "keydown", "DOMMouseScroll", "mousewheel", "mousedown", "touchstart", "touchmove"], function( i, event ) {
asyncTest( "Should clear timeout on " + event, function() {
expect( 3 );
var triggerEvent = function() {
$( "#qunit-fixture" ).trigger( event );
equal( $( "#qunit-fixture" ).data( "idleTimer" ), "active", "State should be active" );
};
// trigger event every now and then to prevent going inactive
setTimeout( triggerEvent, 100 );
setTimeout( triggerEvent, 200 );
setTimeout( triggerEvent, 300 );
setTimeout( function() {
$.idleTimer( "destroy" );
start();
}, 350);
$( "#qunit-fixture" ).idleTimer( 200 );
});
});
test( "Elapsed time is a number", function() {
expect( 2 );
equal( typeof $.idleTimer( "getElapsedTime" ), "number", "Elapsed time should be a number" );
equal( typeof $(document).idleTimer( "getElapsedTime" ), "number", "Elapsed time should be a number" );
});
}(jQuery));