Skip to content

Commit

Permalink
Test idle event and fix invalid value for jmpress property in eventData
Browse files Browse the repository at this point in the history
  • Loading branch information
FagnerMartinsBrack committed Jan 13, 2015
1 parent ef8dfff commit f32f962
Show file tree
Hide file tree
Showing 4 changed files with 5,786 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/components/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,9 @@
if ( current.idleTimeout ) {
clearTimeout( current.idleTimeout );
}
current.idleTimeout = setTimeout(function() {
current.idleTimeout = setTimeout($.proxy(function() {
callCallback.call( this, "idle", delegated, callbackData );
}, Math.max( 1, settings.transitionDuration - 100 ) );
}, this ), Math.max( 1, settings.transitionDuration - 100 ) );

return delegated;
}
Expand Down
31 changes: 30 additions & 1 deletion test/components/core.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global QUnit, module, test, asyncTest, expect, start, stop, ok, equal, notEqual, deepEqual,
* notDeepEqual, strictEqual, notStrictEqual, raises */
* notDeepEqual, strictEqual, notStrictEqual, raises, sinon */
(function( $ ) {

"use strict";
Expand Down Expand Up @@ -211,4 +211,33 @@
strictEqual( count, 1, "event fired" );
});

module( "async callbacks", {
setup: function() {
this.fixture = "#qunit-fixture #jmpress";
this.clock = sinon.useFakeTimers();
},
teardown: function() {
this.clock.restore();
}
});

test( "should fire idle event", function() {
expect( 2 );
var jmpress,
count = 0;

$( this.fixture ).jmpress();
$( this.fixture ).jmpress( "idle", function( element, eventData ) {
jmpress = eventData.jmpress;
count += 1;
});

// settings.transitionDuration - 100
// 1500 - 100
this.clock.tick( 1400 );

strictEqual( count, 1, "event fired" );
ok( !!jmpress, "should have a valid value on eventData.jmpress" );
});

}( jQuery ));
1 change: 1 addition & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<script>jQuery.noConflict()</script>
<link rel="stylesheet" href="libs/qunit/qunit.css" media="screen">
<script src="libs/qunit/qunit.js"></script>
<script src="libs/sinon/sinon.js"></script>

<!-- SRC -->
<script src="../dist/jmpress.all.js"></script>
Expand Down

0 comments on commit f32f962

Please sign in to comment.