define( [
+ "qunit",
"jquery",
"./helper",
"ui/widgets/spinner"
-], function( $, testHelper ) {
+], function( QUnit, $, testHelper ) {
var simulateKeyDownUp = testHelper.simulateKeyDownUp;
-module( "spinner: core" );
+QUnit.module( "spinner: core" );
-test( "markup structure", function( assert ) {
- expect( 6 );
+QUnit.test( "markup structure", function( assert ) {
+ assert.expect( 6 );
var element = $( "#spin" ).spinner(),
spinner = element.spinner( "widget" ),
up = spinner.find( ".ui-spinner-up" ),
assert.hasClasses( element, "ui-spinner-input" );
assert.hasClasses( spinner, "ui-spinner ui-widget ui-widget-content" );
assert.hasClasses( up, "ui-spinner-button ui-spinner-up ui-widget" );
- equal( up.length, 1, "Spinner contains exactly one up button" );
+ assert.equal( up.length, 1, "Spinner contains exactly one up button" );
assert.hasClasses( down, "ui-spinner-button ui-spinner-down ui-widget" );
- equal( down.length, 1, "Spinner contains exactly one down button" );
+ assert.equal( down.length, 1, "Spinner contains exactly one down button" );
} );
-test( "keydown UP on input, increases value not greater than max", function() {
- expect( 5 );
+QUnit.test( "keydown UP on input, increases value not greater than max", function( assert ) {
+ assert.expect( 5 );
var element = $( "#spin" ).val( 70 ).spinner( {
max: 100,
step: 10
} );
simulateKeyDownUp( element, $.ui.keyCode.UP );
- equal( element.val(), 80 );
+ assert.equal( element.val(), 80 );
simulateKeyDownUp( element, $.ui.keyCode.UP );
- equal( element.val(), 90 );
+ assert.equal( element.val(), 90 );
simulateKeyDownUp( element, $.ui.keyCode.UP );
- equal( element.val(), 100 );
+ assert.equal( element.val(), 100 );
simulateKeyDownUp( element, $.ui.keyCode.UP );
- equal( element.val(), 100 );
+ assert.equal( element.val(), 100 );
simulateKeyDownUp( element, $.ui.keyCode.UP );
- equal( element.val(), 100 );
+ assert.equal( element.val(), 100 );
} );
-test( "keydown DOWN on input, decreases value not less than min", function() {
- expect( 5 );
+QUnit.test( "keydown DOWN on input, decreases value not less than min", function( assert ) {
+ assert.expect( 5 );
var element = $( "#spin" ).val( 50 ).spinner( {
min: 20,
step: 10
} );
simulateKeyDownUp( element, $.ui.keyCode.DOWN );
- equal( element.val(), 40 );
+ assert.equal( element.val(), 40 );
simulateKeyDownUp( element, $.ui.keyCode.DOWN );
- equal( element.val(), 30 );
+ assert.equal( element.val(), 30 );
simulateKeyDownUp( element, $.ui.keyCode.DOWN );
- equal( element.val(), 20 );
+ assert.equal( element.val(), 20 );
simulateKeyDownUp( element, $.ui.keyCode.DOWN );
- equal( element.val(), 20 );
+ assert.equal( element.val(), 20 );
simulateKeyDownUp( element, $.ui.keyCode.DOWN );
- equal( element.val(), 20 );
+ assert.equal( element.val(), 20 );
} );
-test( "keydown PAGE_UP on input, increases value not greater than max", function() {
- expect( 5 );
+QUnit.test( "keydown PAGE_UP on input, increases value not greater than max", function( assert ) {
+ assert.expect( 5 );
var element = $( "#spin" ).val( 70 ).spinner( {
max: 100,
page: 10
} );
simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
- equal( element.val(), 80 );
+ assert.equal( element.val(), 80 );
simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
- equal( element.val(), 90 );
+ assert.equal( element.val(), 90 );
simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
- equal( element.val(), 100 );
+ assert.equal( element.val(), 100 );
simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
- equal( element.val(), 100 );
+ assert.equal( element.val(), 100 );
simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
- equal( element.val(), 100 );
+ assert.equal( element.val(), 100 );
} );
-test( "keydown PAGE_DOWN on input, decreases value not less than min", function() {
- expect( 5 );
+QUnit.test( "keydown PAGE_DOWN on input, decreases value not less than min", function( assert ) {
+ assert.expect( 5 );
var element = $( "#spin" ).val( 50 ).spinner( {
min: 20,
page: 10
} );
simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
- equal( element.val(), 40 );
+ assert.equal( element.val(), 40 );
simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
- equal( element.val(), 30 );
+ assert.equal( element.val(), 30 );
simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
- equal( element.val(), 20 );
+ assert.equal( element.val(), 20 );
simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
- equal( element.val(), 20 );
+ assert.equal( element.val(), 20 );
simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
- equal( element.val(), 20 );
+ assert.equal( element.val(), 20 );
} );
-asyncTest( "blur input while spinning with UP", function() {
- expect( 3 );
+QUnit.test( "blur input while spinning with UP", function( assert ) {
+ var ready = assert.async();
+ assert.expect( 3 );
var value,
element = $( "#spin" ).val( 10 ).spinner();
function step1() {
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
- equal( element.val(), 11 );
+ assert.equal( element.val(), 11 );
setTimeout( step2, 750 );
}
function step2() {
value = element.val();
- ok( value > 11, "repeating while key is down" );
+ assert.ok( value > 11, "repeating while key is down" );
element.on( "blur", function() {
value = element.val();
}
function step3() {
- equal( element.val(), value, "stopped repeating on blur" );
- start();
+ assert.equal( element.val(), value, "stopped repeating on blur" );
+ ready();
}
element[ 0 ].focus();
setTimeout( step1 );
} );
-test( "mouse click on up button, increases value not greater than max", function() {
- expect( 3 );
+QUnit.test( "mouse click on up button, increases value not greater than max", function( assert ) {
+ assert.expect( 3 );
var element = $( "#spin" ).val( 18 ).spinner( {
max: 20
} ),
button = element.spinner( "widget" ).find( ".ui-spinner-up" );
button.trigger( "mousedown" ).trigger( "mouseup" );
- equal( element.val(), 19 );
+ assert.equal( element.val(), 19 );
button.trigger( "mousedown" ).trigger( "mouseup" );
- equal( element.val(), 20 );
+ assert.equal( element.val(), 20 );
button.trigger( "mousedown" ).trigger( "mouseup" );
- equal( element.val(), 20 );
+ assert.equal( element.val(), 20 );
} );
-test( "mouse click on up button, increases value not greater than max", function() {
- expect( 3 );
+QUnit.test( "mouse click on up button, increases value not greater than max", function( assert ) {
+ assert.expect( 3 );
var element = $( "#spin" ).val( 2 ).spinner( {
min: 0
} ),
button = element.spinner( "widget" ).find( ".ui-spinner-down" );
button.trigger( "mousedown" ).trigger( "mouseup" );
- equal( element.val(), 1 );
+ assert.equal( element.val(), 1 );
button.trigger( "mousedown" ).trigger( "mouseup" );
- equal( element.val(), 0 );
+ assert.equal( element.val(), 0 );
button.trigger( "mousedown" ).trigger( "mouseup" );
- equal( element.val(), 0 );
+ assert.equal( element.val(), 0 );
} );
-test( "mousewheel on input", function() {
- expect( 4 );
+QUnit.test( "mousewheel on input", function( assert ) {
+ assert.expect( 4 );
var element = $( "#spin" ).val( 0 ).spinner( {
step: 2
} );
element.trigger( "mousewheel" );
- equal( element.val(), 0, "mousewheel event without delta does not change value" );
+ assert.equal( element.val(), 0, "mousewheel event without delta does not change value" );
element.trigger( "mousewheel", 1 );
- equal( element.val(), 2 );
+ assert.equal( element.val(), 2 );
element.trigger( "mousewheel", -0.2 );
- equal( element.val(), 0 );
+ assert.equal( element.val(), 0 );
element.trigger( "mousewheel", -15 );
- equal( element.val(), -2 );
+ assert.equal( element.val(), -2 );
} );
-test( "reading HTML5 attributes", function() {
- expect( 6 );
+QUnit.test( "reading HTML5 attributes", function( assert ) {
+ assert.expect( 6 );
var markup = "<input type='number' min='-100' max='100' value='5' step='2'>",
element = $( markup ).spinner();
- equal( element.spinner( "option", "min" ), -100, "min from markup" );
- equal( element.spinner( "option", "max" ), 100, "max from markup" );
- equal( element.spinner( "option", "step" ), 2, "step from markup" );
+ assert.equal( element.spinner( "option", "min" ), -100, "min from markup" );
+ assert.equal( element.spinner( "option", "max" ), 100, "max from markup" );
+ assert.equal( element.spinner( "option", "step" ), 2, "step from markup" );
element = $( markup ).spinner( {
min: -200,
max: 200,
step: 5
} );
- equal( element.spinner( "option", "min" ), -200, "min from options" );
- equal( element.spinner( "option", "max" ), 200, "max from options" );
- equal( element.spinner( "option", "step" ), 5, "stop from options" );
+ assert.equal( element.spinner( "option", "min" ), -200, "min from options" );
+ assert.equal( element.spinner( "option", "max" ), 200, "max from options" );
+ assert.equal( element.spinner( "option", "step" ), 5, "stop from options" );
} );
-test( "ARIA attributes", function() {
- expect( 9 );
+QUnit.test( "ARIA attributes", function( assert ) {
+ assert.expect( 9 );
var element = $( "#spin" ).val( 2 ).spinner( { min: -5, max: 5 } );
- equal( element.attr( "role" ), "spinbutton", "role" );
- equal( element.attr( "aria-valuemin" ), "-5", "aria-valuemin" );
- equal( element.attr( "aria-valuemax" ), "5", "aria-valuemax" );
- equal( element.attr( "aria-valuenow" ), "2", "aria-valuenow" );
+ assert.equal( element.attr( "role" ), "spinbutton", "role" );
+ assert.equal( element.attr( "aria-valuemin" ), "-5", "aria-valuemin" );
+ assert.equal( element.attr( "aria-valuemax" ), "5", "aria-valuemax" );
+ assert.equal( element.attr( "aria-valuenow" ), "2", "aria-valuenow" );
element.spinner( "stepUp" );
- equal( element.attr( "aria-valuenow" ), "3", "stepUp 1 step changes aria-valuenow" );
+ assert.equal( element.attr( "aria-valuenow" ), "3", "stepUp 1 step changes aria-valuenow" );
element.spinner( "option", { min: -10, max: 10 } );
- equal( element.attr( "aria-valuemin" ), "-10", "min option changed aria-valuemin changes" );
- equal( element.attr( "aria-valuemax" ), "10", "max option changed aria-valuemax changes" );
+ assert.equal( element.attr( "aria-valuemin" ), "-10", "min option changed aria-valuemin changes" );
+ assert.equal( element.attr( "aria-valuemax" ), "10", "max option changed aria-valuemax changes" );
element.spinner( "option", "min", null );
- equal( element.attr( "aria-valuemin" ), undefined, "aria-valuemin not set when no min" );
+ assert.equal( element.attr( "aria-valuemin" ), undefined, "aria-valuemin not set when no min" );
element.spinner( "option", "max", null );
- equal( element.attr( "aria-valuemax" ), undefined, "aria-valuemax not set when no max" );
+ assert.equal( element.attr( "aria-valuemax" ), undefined, "aria-valuemax not set when no max" );
} );
-test( "focus text field when pressing button", function() {
- expect( 2 );
+QUnit.test( "focus text field when pressing button", function( assert ) {
+ assert.expect( 2 );
var element = $( "#spin" ).spinner();
$( "body" ).trigger( "focus" );
- ok( element[ 0 ] !== document.activeElement, "not focused before" );
+ assert.ok( element[ 0 ] !== document.activeElement, "not focused before" );
element.spinner( "widget" ).find( ".ui-spinner-up" ).trigger( "mousedown" );
- ok( element[ 0 ] === document.activeElement, "focused after" );
+ assert.ok( element[ 0 ] === document.activeElement, "focused after" );
} );
-test( "don't clear invalid value on blur", function() {
- expect( 1 );
+QUnit.test( "don't clear invalid value on blur", function( assert ) {
+ assert.expect( 1 );
var element = $( "#spin" ).spinner();
element.trigger( "focus" ).val( "a" ).trigger( "blur" );
- equal( element.val(), "a" );
+ assert.equal( element.val(), "a" );
} );
-test( "precision", function() {
- expect( 2 );
+QUnit.test( "precision", function( assert ) {
+ assert.expect( 2 );
var element = $( "#spin" ).val( 0.05 ).spinner( {
step: 0.0001
} );
element.spinner( "stepUp" );
- equal( element.val(), "0.0501", "precision from step" );
+ assert.equal( element.val(), "0.0501", "precision from step" );
element.val( 1.05 ).spinner( "option", {
step: 1,
min: -9.95
} );
element.spinner( "stepDown" );
- equal( element.val(), "0.05", "precision from min" );
+ assert.equal( element.val(), "0.05", "precision from min" );
} );
} );
define( [
+ "qunit",
"jquery",
"ui/widgets/spinner"
-], function( $ ) {
+], function( QUnit, $ ) {
var originalSpinner = $.ui.spinner.prototype;
-module( "spinner: deprecated", {
- setup: function() {
+QUnit.module( "spinner: deprecated", {
+ beforeEach: function() {
$.widget( "ui.spinner", $.ui.spinner, {
_uiSpinnerHtml: function() {
return "<span class='spin-wrap'>";
} );
},
- teardown: function() {
+ afterEach: function() {
$.ui.spinner.prototype = originalSpinner;
}
} );
-test( "markup structure - custom", function( assert ) {
- expect( 2 );
+QUnit.test( "markup structure - custom", function( assert ) {
+ assert.expect( 2 );
var element = $( "#spin" ).spinner(),
spinner = element.spinner( "widget" ),
up = spinner.find( ".ui-spinner-up" );
define( [
+ "qunit",
"jquery",
"./helper",
"ui/widgets/spinner"
-], function( $, testHelper ) {
+], function( QUnit, $, testHelper ) {
var simulateKeyDownUp = testHelper.simulateKeyDownUp;
-module( "spinner: events" );
+QUnit.module( "spinner: events" );
-test( "start", function() {
- expect( 10 );
+QUnit.test( "start", function( assert ) {
+ assert.expect( 10 );
var element = $( "#spin" ).spinner();
function shouldStart( expectation, msg ) {
element.spinner( "option", "start", function() {
- ok( expectation, msg );
+ assert.ok( expectation, msg );
} );
}
element.spinner( "value", 999 );
} );
-test( "spin", function() {
- expect( 10 );
+QUnit.test( "spin", function( assert ) {
+ assert.expect( 10 );
var element = $( "#spin" ).spinner();
function shouldSpin( expectation, msg ) {
element.spinner( "option", "spin", function() {
- ok( expectation, msg );
+ assert.ok( expectation, msg );
} );
}
element.spinner( "value", 999 );
} );
-test( "stop", function() {
- expect( 10 );
+QUnit.test( "stop", function( assert ) {
+ assert.expect( 10 );
var element = $( "#spin" ).spinner();
function shouldStop( expectation, msg ) {
element.spinner( "option", "stop", function() {
- ok( expectation, msg );
+ assert.ok( expectation, msg );
} );
}
element.spinner( "value", 999 );
} );
-asyncTest( "change", function() {
- expect( 12 );
+QUnit.test( "change", function( assert ) {
+ var ready = assert.async();
+ assert.expect( 12 );
var element = $( "#spin" ).spinner();
function shouldChange( expectation, msg ) {
element.spinner( "option", "change", function() {
- ok( expectation, msg );
+ assert.ok( expectation, msg );
} );
}
shouldChange( false, "min, value not changed" );
element.spinner( "option", "min", 200 );
- start();
+ ready();
}
setTimeout( step1 );
define( [
+ "qunit",
"jquery",
"./helper",
"ui/widgets/spinner"
-], function( $, testHelper ) {
+], function( QUnit, $, testHelper ) {
var simulateKeyDownUp = testHelper.simulateKeyDownUp;
-module( "spinner: methods" );
+QUnit.module( "spinner: methods" );
-test( "destroy", function( assert ) {
- expect( 1 );
+QUnit.test( "destroy", function( assert ) {
+ assert.expect( 1 );
assert.domEqual( "#spin", function() {
$( "#spin" ).spinner().spinner( "destroy" );
} );
} );
-test( "disable", function( assert ) {
- expect( 15 );
+QUnit.test( "disable", function( assert ) {
+ assert.expect( 15 );
var element = $( "#spin" ).val( 2 ).spinner(),
wrapper = $( "#spin" ).spinner( "widget" );
assert.lacksClasses( wrapper, "ui-spinner-disabled" );
- ok( !element.is( ":disabled" ), "before: input does not have disabled attribute" );
+ assert.ok( !element.is( ":disabled" ), "before: input does not have disabled attribute" );
element.spinner( "disable" );
assert.hasClasses( wrapper, "ui-state-disabled ui-spinner-disabled" );
- ok( !wrapper.attr( "aria-disabled" ), "after: wrapper does not have aria-disabled attr" );
- ok( element.is( ":disabled" ), "after: input has disabled attribute" );
+ assert.ok( !wrapper.attr( "aria-disabled" ), "after: wrapper does not have aria-disabled attr" );
+ assert.ok( element.is( ":disabled" ), "after: input has disabled attribute" );
simulateKeyDownUp( element, $.ui.keyCode.UP );
- equal( 2, element.val(), "keyboard - value does not change on key UP" );
+ assert.equal( 2, element.val(), "keyboard - value does not change on key UP" );
simulateKeyDownUp( element, $.ui.keyCode.DOWN );
- equal( 2, element.val(), "keyboard - value does not change on key DOWN" );
+ assert.equal( 2, element.val(), "keyboard - value does not change on key DOWN" );
simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP );
- equal( 2, element.val(), "keyboard - value does not change on key PGUP" );
+ assert.equal( 2, element.val(), "keyboard - value does not change on key PGUP" );
simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN );
- equal( 2, element.val(), "keyboard - value does not change on key PGDN" );
+ assert.equal( 2, element.val(), "keyboard - value does not change on key PGDN" );
wrapper.find( ".ui-spinner-up" ).trigger( "mousedown" ).trigger( "mouseup" );
- equal( 2, element.val(), "mouse - value does not change on clicking up button" );
+ assert.equal( 2, element.val(), "mouse - value does not change on clicking up button" );
wrapper.find( ".ui-spinner-down" ).trigger( "mousedown" ).trigger( "mouseup" );
- equal( 2, element.val(), "mouse - value does not change on clicking down button" );
+ assert.equal( 2, element.val(), "mouse - value does not change on clicking down button" );
element.spinner( "stepUp", 6 );
- equal( 8, element.val(), "script - stepUp 6 steps changes value" );
+ assert.equal( 8, element.val(), "script - stepUp 6 steps changes value" );
element.spinner( "stepDown" );
- equal( 7, element.val(), "script - stepDown 1 step changes value" );
+ assert.equal( 7, element.val(), "script - stepDown 1 step changes value" );
element.spinner( "pageUp" );
- equal( 17, element.val(), "script - pageUp 1 page changes value" );
+ assert.equal( 17, element.val(), "script - pageUp 1 page changes value" );
element.spinner( "pageDown" );
- equal( 7, element.val(), "script - pageDown 1 page changes value" );
+ assert.equal( 7, element.val(), "script - pageDown 1 page changes value" );
} );
-test( "enable", function( assert ) {
- expect( 5 );
+QUnit.test( "enable", function( assert ) {
+ assert.expect( 5 );
var element = $( "#spin" ).val( 1 ).spinner( { disabled: true } ),
wrapper = element.spinner( "widget" );
assert.hasClasses( wrapper, "ui-spinner-disabled" );
- ok( element.is( ":disabled" ), "before: input has disabled attribute" );
+ assert.ok( element.is( ":disabled" ), "before: input has disabled attribute" );
element.spinner( "enable" );
assert.lacksClasses( wrapper, "ui-spinner-disabled" );
- ok( !element.is( ":disabled" ), "after: input does not have disabled attribute" );
+ assert.ok( !element.is( ":disabled" ), "after: input does not have disabled attribute" );
simulateKeyDownUp( element, $.ui.keyCode.UP );
- equal( 2, element.val(), "keyboard - value changes on key UP" );
+ assert.equal( 2, element.val(), "keyboard - value changes on key UP" );
} );
-test( "isValid", function() {
- expect( 8 );
+QUnit.test( "isValid", function( assert ) {
+ assert.expect( 8 );
var element = $( "#spin" ).spinner( {
min: 0,
max: 10,
step: 2
} ),
spinner = element.spinner( "instance" );
- ok( !spinner.isValid(), "initial state is invalid" );
+ assert.ok( !spinner.isValid(), "initial state is invalid" );
element.val( "this is not a number" );
- ok( !spinner.isValid(), "text string is not valid" );
+ assert.ok( !spinner.isValid(), "text string is not valid" );
element.val( "0" );
- ok( spinner.isValid(), "min value is valid" );
+ assert.ok( spinner.isValid(), "min value is valid" );
element.val( "10" );
- ok( spinner.isValid(), "max value is valid" );
+ assert.ok( spinner.isValid(), "max value is valid" );
element.val( "4" );
- ok( spinner.isValid(), "inbetween step is valid" );
+ assert.ok( spinner.isValid(), "inbetween step is valid" );
element.val( "-1" );
- ok( !spinner.isValid(), "below min is invalid" );
+ assert.ok( !spinner.isValid(), "below min is invalid" );
element.val( "11" );
- ok( !spinner.isValid(), "above max is invalid" );
+ assert.ok( !spinner.isValid(), "above max is invalid" );
element.val( "1" );
- ok( !spinner.isValid(), "step mismatch is invalid" );
+ assert.ok( !spinner.isValid(), "step mismatch is invalid" );
} );
-test( "pageDown", function() {
- expect( 4 );
+QUnit.test( "pageDown", function( assert ) {
+ assert.expect( 4 );
var element = $( "#spin" ).val( -12 ).spinner( {
page: 20,
min: -100
} );
element.spinner( "pageDown" );
- equal( element.val(), -32, "pageDown 1 page" );
+ assert.equal( element.val(), -32, "pageDown 1 page" );
element.spinner( "pageDown", 3 );
- equal( element.val(), -92, "pageDown 3 pages" );
+ assert.equal( element.val(), -92, "pageDown 3 pages" );
element.spinner( "pageDown" );
- equal( element.val(), -100, "value close to min and pageDown 1 page" );
+ assert.equal( element.val(), -100, "value close to min and pageDown 1 page" );
element.spinner( "pageDown", 10 );
- equal( element.val(), -100, "value at min and pageDown 10 pages" );
+ assert.equal( element.val(), -100, "value at min and pageDown 10 pages" );
} );
-test( "pageUp", function() {
- expect( 4 );
+QUnit.test( "pageUp", function( assert ) {
+ assert.expect( 4 );
var element = $( "#spin" ).val( 12 ).spinner( {
page: 20,
max: 100
} );
element.spinner( "pageUp" );
- equal( element.val(), 32, "pageUp 1 page" );
+ assert.equal( element.val(), 32, "pageUp 1 page" );
element.spinner( "pageUp", 3 );
- equal( element.val(), 92, "pageUp 3 pages" );
+ assert.equal( element.val(), 92, "pageUp 3 pages" );
element.spinner( "pageUp" );
- equal( element.val(), 100, "value close to max and pageUp 1 page" );
+ assert.equal( element.val(), 100, "value close to max and pageUp 1 page" );
element.spinner( "pageUp", 10 );
- equal( element.val(), 100, "value at max and pageUp 10 pages" );
+ assert.equal( element.val(), 100, "value at max and pageUp 10 pages" );
} );
-test( "stepDown", function() {
- expect( 4 );
+QUnit.test( "stepDown", function( assert ) {
+ assert.expect( 4 );
var element = $( "#spin" ).val( 0 ).spinner( {
step: 2,
min: -15
} );
element.spinner( "stepDown" );
- equal( element.val(), "-1", "stepDown 1 step" );
+ assert.equal( element.val(), "-1", "stepDown 1 step" );
element.spinner( "stepDown", 5 );
- equal( element.val(), "-11", "stepDown 5 steps" );
+ assert.equal( element.val(), "-11", "stepDown 5 steps" );
element.spinner( "stepDown", 4 );
- equal( element.val(), "-15", "close to min and stepDown 4 steps" );
+ assert.equal( element.val(), "-15", "close to min and stepDown 4 steps" );
element.spinner( "stepDown" );
- equal( element.val(), "-15", "at min and stepDown 1 step" );
+ assert.equal( element.val(), "-15", "at min and stepDown 1 step" );
} );
-test( "stepUp", function() {
- expect( 4 );
+QUnit.test( "stepUp", function( assert ) {
+ assert.expect( 4 );
var element = $( "#spin" ).val( 0 ).spinner( {
step: 2,
max: 16
} );
element.spinner( "stepUp" );
- equal( element.val(), 2, "stepUp 1 step" );
+ assert.equal( element.val(), 2, "stepUp 1 step" );
element.spinner( "stepUp", 5 );
- equal( element.val(), 12, "stepUp 5 steps" );
+ assert.equal( element.val(), 12, "stepUp 5 steps" );
element.spinner( "stepUp", 4 );
- equal( element.val(), 16, "close to max and stepUp 4 steps" );
+ assert.equal( element.val(), 16, "close to max and stepUp 4 steps" );
element.spinner( "stepUp" );
- equal( element.val(), 16, "at max and stepUp 1 step" );
+ assert.equal( element.val(), 16, "at max and stepUp 1 step" );
} );
-test( "value", function() {
- expect( 2 );
+QUnit.test( "value", function( assert ) {
+ assert.expect( 2 );
var element = $( "#spin" ).val( 0 ).spinner( {
step: 3
} );
element.spinner( "value", 10 );
- equal( element.val(), 9, "change value via value method" );
+ assert.equal( element.val(), 9, "change value via value method" );
- equal( element.spinner( "value" ), 9, "get value via value method" );
+ assert.equal( element.spinner( "value" ), 9, "get value via value method" );
} );
-test( "widget", function() {
- expect( 2 );
+QUnit.test( "widget", function( assert ) {
+ assert.expect( 2 );
var element = $( "#spin" ).spinner(),
widgetElement = element.spinner( "widget" );
- equal( widgetElement.length, 1, "one element" );
- strictEqual( widgetElement[ 0 ], element.parent()[ 0 ], "parent element" );
+ assert.equal( widgetElement.length, 1, "one element" );
+ assert.strictEqual( widgetElement[ 0 ], element.parent()[ 0 ], "parent element" );
} );
} );
define( [
+ "qunit",
"jquery",
"ui/widgets/spinner",
"globalize",
"globalize/ja-JP"
-], function( $ ) {
+], function( QUnit, $ ) {
-module( "spinner: options" );
+QUnit.module( "spinner: options" );
-// culture is tested after numberFormat, since it depends on numberFormat
+// Culture is tested after numberFormat, since it depends on numberFormat
-test( "icons: default ", function( assert ) {
- expect( 4 );
+QUnit.test( "icons: default ", function( assert ) {
+ assert.expect( 4 );
var element = $( "#spin" ).val( 0 ).spinner();
assert.hasClasses( element.spinner( "widget" ).find( ".ui-icon:first" ),
"ui-icon ui-icon-triangle-1-n" );
"ui-icon ui-icon-caret-1-s" );
} );
-test( "icons: custom ", function( assert ) {
- expect( 2 );
+QUnit.test( "icons: custom ", function( assert ) {
+ assert.expect( 2 );
var element = $( "#spin" ).val( 0 ).spinner( {
icons: {
down: "custom-down",
assert.hasClasses( element.find( ".ui-icon:last" ), "ui-icon custom-down" );
} );
-test( "incremental, false", function() {
- expect( 100 );
+QUnit.test( "incremental, false", function( assert ) {
+ assert.expect( 100 );
var i,
prev = 0,
element = $( "#spin" ).val( prev ).spinner( {
incremental: false,
spin: function( event, ui ) {
- equal( ui.value - prev, 1 );
+ assert.equal( ui.value - prev, 1 );
prev = ui.value;
}
} );
element.simulate( "keyup", { keyCode: $.ui.keyCode.UP } );
} );
-test( "incremental, true", function() {
- expect( 100 );
+QUnit.test( "incremental, true", function( assert ) {
+ assert.expect( 100 );
function fill( num, val ) {
return $.map( new Array( num ), function() {
var i,
prev = 0,
expected = [].concat( fill( 18, 1 ), fill( 37, 2 ), fill( 14, 3 ),
- fill( 9, 4 ), fill( 6, 5 ), fill( 5, 6 ), fill ( 5, 7 ),
+ fill( 9, 4 ), fill( 6, 5 ), fill( 5, 6 ), fill( 5, 7 ),
fill( 4, 8 ), fill( 2, 9 ) ),
element = $( "#spin" ).val( prev ).spinner( {
incremental: true,
spin: function( event, ui ) {
- equal( ui.value - prev, expected[ i ] );
+ assert.equal( ui.value - prev, expected[ i ] );
prev = ui.value;
}
} );
element.simulate( "keyup", { keyCode: $.ui.keyCode.UP } );
} );
-test( "incremental, function", function() {
- expect( 100 );
+QUnit.test( "incremental, function", function( assert ) {
+ assert.expect( 100 );
var i,
prev = 0,
return i;
},
spin: function( event, ui ) {
- equal( ui.value - prev, i + 1 );
+ assert.equal( ui.value - prev, i + 1 );
prev = ui.value;
}
} );
element.simulate( "keyup", { keyCode: $.ui.keyCode.UP } );
} );
-test( "numberFormat, number", function() {
- expect( 2 );
+QUnit.test( "numberFormat, number", function( assert ) {
+ assert.expect( 2 );
var element = $( "#spin" ).val( 0 ).spinner( { numberFormat: "n" } );
- equal( element.val(), "0.00", "formatted on init" );
+ assert.equal( element.val(), "0.00", "formatted on init" );
element.spinner( "stepUp" );
- equal( element.val(), "1.00", "formatted after step" );
+ assert.equal( element.val(), "1.00", "formatted after step" );
} );
-test( "numberFormat, number, simple", function() {
- expect( 2 );
+QUnit.test( "numberFormat, number, simple", function( assert ) {
+ assert.expect( 2 );
var element = $( "#spin" ).val( 0 ).spinner( { numberFormat: "n0" } );
- equal( element.val(), "0", "formatted on init" );
+ assert.equal( element.val(), "0", "formatted on init" );
element.spinner( "stepUp" );
- equal( element.val(), "1", "formatted after step" );
+ assert.equal( element.val(), "1", "formatted after step" );
} );
-test( "numberFormat, currency", function() {
- expect( 2 );
+QUnit.test( "numberFormat, currency", function( assert ) {
+ assert.expect( 2 );
var element = $( "#spin" ).val( 0 ).spinner( { numberFormat: "C" } );
- equal( element.val(), "$0.00", "formatted on init" );
+ assert.equal( element.val(), "$0.00", "formatted on init" );
element.spinner( "stepUp" );
- equal( element.val(), "$1.00", "formatted after step" );
+ assert.equal( element.val(), "$1.00", "formatted after step" );
} );
-test( "numberFormat, change", function() {
- expect( 2 );
+QUnit.test( "numberFormat, change", function( assert ) {
+ assert.expect( 2 );
var element = $( "#spin" ).val( 5 ).spinner( { numberFormat: "n1" } );
- equal( element.val(), "5.0", "formatted on init" );
+ assert.equal( element.val(), "5.0", "formatted on init" );
element.spinner( "option", "numberFormat", "c" );
- equal( element.val(), "$5.00", "formatted after change" );
+ assert.equal( element.val(), "$5.00", "formatted after change" );
} );
-test( "culture, null", function() {
- expect( 2 );
+QUnit.test( "culture, null", function( assert ) {
+ assert.expect( 2 );
Globalize.culture( "ja-JP" );
var element = $( "#spin" ).val( 0 ).spinner( { numberFormat: "C" } );
- equal( element.val(), "¥0", "formatted on init" );
+ assert.equal( element.val(), "¥0", "formatted on init" );
element.spinner( "stepUp" );
- equal( element.val(), "¥1", "formatted after step" );
+ assert.equal( element.val(), "¥1", "formatted after step" );
// Reset culture
Globalize.culture( "default" );
} );
-test( "currency, ja-JP", function() {
- expect( 2 );
+QUnit.test( "currency, ja-JP", function( assert ) {
+ assert.expect( 2 );
var element = $( "#spin" ).val( 0 ).spinner( {
numberFormat: "C",
culture: "ja-JP"
} );
- equal( element.val(), "¥0", "formatted on init" );
+ assert.equal( element.val(), "¥0", "formatted on init" );
element.spinner( "stepUp" );
- equal( element.val(), "¥1", "formatted after step" );
+ assert.equal( element.val(), "¥1", "formatted after step" );
} );
-test( "currency, change", function() {
- expect( 2 );
+QUnit.test( "currency, change", function( assert ) {
+ assert.expect( 2 );
var element = $( "#spin" ).val( 5 ).spinner( {
numberFormat: "C",
culture: "ja-JP"
} );
- equal( element.val(), "¥5", "formatted on init" );
+ assert.equal( element.val(), "¥5", "formatted on init" );
element.spinner( "option", "culture", "en" );
- equal( element.val(), "$5.00", "formatted after change" );
+ assert.equal( element.val(), "$5.00", "formatted after change" );
} );
-test( "max", function() {
- expect( 3 );
+QUnit.test( "max", function( assert ) {
+ assert.expect( 3 );
var element = $( "#spin" ).val( 1000 ).spinner( { max: 100 } );
- equal( element.val(), 1000, "value not constrained on init" );
+ assert.equal( element.val(), 1000, "value not constrained on init" );
element.spinner( "value", 1000 );
- equal( element.val(), 100, "max constrained in value method" );
+ assert.equal( element.val(), 100, "max constrained in value method" );
element.val( 1000 ).trigger( "blur" );
- equal( element.val(), 1000, "max not constrained if manual entry" );
+ assert.equal( element.val(), 1000, "max not constrained if manual entry" );
} );
-test( "max, string", function() {
- expect( 3 );
+QUnit.test( "max, string", function( assert ) {
+ assert.expect( 3 );
var element = $( "#spin" )
.val( 1000 )
.spinner( {
numberFormat: "C",
culture: "en"
} );
- equal( element.val(), "$1,000.00", "value not constrained on init" );
- equal( element.spinner( "option", "max" ), 100, "option converted to number" );
+ assert.equal( element.val(), "$1,000.00", "value not constrained on init" );
+ assert.equal( element.spinner( "option", "max" ), 100, "option converted to number" );
element.spinner( "value", 1000 );
- equal( element.val(), "$100.00", "max constrained in value method" );
+ assert.equal( element.val(), "$100.00", "max constrained in value method" );
} );
-test( "min", function() {
- expect( 3 );
+QUnit.test( "min", function( assert ) {
+ assert.expect( 3 );
var element = $( "#spin" ).val( -1000 ).spinner( { min: -100 } );
- equal( element.val(), -1000, "value not constrained on init" );
+ assert.equal( element.val(), -1000, "value not constrained on init" );
element.spinner( "value", -1000 );
- equal( element.val(), -100, "min constrained in value method" );
+ assert.equal( element.val(), -100, "min constrained in value method" );
element.val( -1000 ).trigger( "blur" );
- equal( element.val(), -1000, "min not constrained if manual entry" );
+ assert.equal( element.val(), -1000, "min not constrained if manual entry" );
} );
-test( "min, string", function() {
- expect( 3 );
+QUnit.test( "min, string", function( assert ) {
+ assert.expect( 3 );
var element = $( "#spin" )
.val( -1000 )
.spinner( {
numberFormat: "C",
culture: "en"
} );
- equal( element.val(), "($1,000.00)", "value not constrained on init" );
- equal( element.spinner( "option", "min" ), -100, "option converted to number" );
+ assert.equal( element.val(), "($1,000.00)", "value not constrained on init" );
+ assert.equal( element.spinner( "option", "min" ), -100, "option converted to number" );
element.spinner( "value", -1000 );
- equal( element.val(), "($100.00)", "min constrained in value method" );
+ assert.equal( element.val(), "($100.00)", "min constrained in value method" );
} );
-test( "step, 2", function() {
- expect( 3 );
+QUnit.test( "step, 2", function( assert ) {
+ assert.expect( 3 );
var element = $( "#spin" ).val( 0 ).spinner( { step: 2 } );
element.spinner( "stepUp" );
- equal( element.val(), "2", "stepUp" );
+ assert.equal( element.val(), "2", "stepUp" );
element.spinner( "value", "10.5" );
- equal( element.val(), "10", "value reset to 10" );
+ assert.equal( element.val(), "10", "value reset to 10" );
element.val( "4.5" );
element.spinner( "stepUp" );
- equal( element.val(), "6", "stepUp" );
+ assert.equal( element.val(), "6", "stepUp" );
} );
-test( "step, 0.7", function() {
- expect( 1 );
+QUnit.test( "step, 0.7", function( assert ) {
+ assert.expect( 1 );
var element = $( "#spin" ).val( 0 ).spinner( {
step: 0.7
} );
element.spinner( "stepUp" );
- equal( element.val(), "0.7", "stepUp" );
+ assert.equal( element.val(), "0.7", "stepUp" );
} );
-test( "step, string", function() {
- expect( 2 );
+QUnit.test( "step, string", function( assert ) {
+ assert.expect( 2 );
var element = $( "#spin" ).val( 0 ).spinner( {
step: "$0.70",
numberFormat: "C",
culture: "en"
} );
- equal( element.spinner( "option", "step" ), 0.7, "option converted to number" );
+ assert.equal( element.spinner( "option", "step" ), 0.7, "option converted to number" );
element.spinner( "stepUp" );
- equal( element.val(), "$0.70", "stepUp" );
+ assert.equal( element.val(), "$0.70", "stepUp" );
} );
} );