mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Form: Shift form-reset-mixin to use no globals
This commit is contained in:
parent
3dd45b1ae6
commit
f0c8b77123
@ -1,12 +1,13 @@
|
||||
define( [
|
||||
"qunit",
|
||||
"jquery",
|
||||
"lib/common",
|
||||
"ui/widget",
|
||||
"ui/form-reset-mixin"
|
||||
], function( $, common ) {
|
||||
], function( QUnit, $, common ) {
|
||||
|
||||
module( "widget factory", {
|
||||
setup: function() {
|
||||
QUnit.module( "widget factory", {
|
||||
beforeEach: function() {
|
||||
$.widget( "ui.testWidget", [ $.ui.formResetMixin, {
|
||||
_create: function() {
|
||||
this._bindFormResetHandler();
|
||||
@ -22,7 +23,7 @@ module( "widget factory", {
|
||||
$.ui.testWidget.refreshed = [];
|
||||
},
|
||||
|
||||
teardown: function() {
|
||||
afterEach: function() {
|
||||
delete $.ui.testWidget;
|
||||
delete $.fn.testWidget;
|
||||
}
|
||||
@ -30,8 +31,9 @@ module( "widget factory", {
|
||||
|
||||
common.testJshint( "form-reset-mixin" );
|
||||
|
||||
asyncTest( "form reset", function() {
|
||||
expect( 2 );
|
||||
QUnit.test( "form reset", function( assert ) {
|
||||
var ready = assert.async();
|
||||
assert.expect( 2 );
|
||||
|
||||
var form = $( "#main" );
|
||||
var inputs = form.find( "input" );
|
||||
@ -39,18 +41,19 @@ asyncTest( "form reset", function() {
|
||||
inputs.testWidget();
|
||||
form.on( "reset", function() {
|
||||
setTimeout( function() {
|
||||
deepEqual( $.ui.testWidget.refreshed, [ "input1", "input2", "input3", "input4" ],
|
||||
assert.deepEqual( $.ui.testWidget.refreshed, [ "input1", "input2", "input3", "input4" ],
|
||||
"All widgets are refreshed on form reset" );
|
||||
equal( form.data( "ui-form-reset-instances" ).length, 4,
|
||||
assert.equal( form.data( "ui-form-reset-instances" ).length, 4,
|
||||
"All widget instances are tracked against the form" );
|
||||
start();
|
||||
ready();
|
||||
} );
|
||||
} );
|
||||
form[ 0 ].reset();
|
||||
} );
|
||||
|
||||
asyncTest( "destroy", function() {
|
||||
expect( 2 );
|
||||
QUnit.test( "destroy", function( assert ) {
|
||||
var ready = assert.async();
|
||||
assert.expect( 2 );
|
||||
|
||||
var form = $( "#main" );
|
||||
var inputs = form.find( "input" );
|
||||
@ -62,18 +65,19 @@ asyncTest( "destroy", function() {
|
||||
|
||||
form.on( "reset", function() {
|
||||
setTimeout( function() {
|
||||
deepEqual( $.ui.testWidget.refreshed, [ "input1", "input3", "input4" ],
|
||||
assert.deepEqual( $.ui.testWidget.refreshed, [ "input1", "input3", "input4" ],
|
||||
"All widgets are refreshed on form reset" );
|
||||
deepEqual( form.data( "ui-form-reset-instances" ).length, 3,
|
||||
assert.deepEqual( form.data( "ui-form-reset-instances" ).length, 3,
|
||||
"All widget instances are tracked against the form" );
|
||||
start();
|
||||
ready();
|
||||
} );
|
||||
} );
|
||||
form[ 0 ].reset();
|
||||
} );
|
||||
|
||||
asyncTest( "destroy all", function() {
|
||||
expect( 2 );
|
||||
QUnit.test( "destroy all", function( assert ) {
|
||||
var ready = assert.async();
|
||||
assert.expect( 2 );
|
||||
|
||||
var form = $( "#main" );
|
||||
|
||||
@ -83,10 +87,10 @@ asyncTest( "destroy all", function() {
|
||||
|
||||
form.on( "reset", function() {
|
||||
setTimeout( function() {
|
||||
deepEqual( $.ui.testWidget.refreshed, [], "No widgets are refreshed after destroy" );
|
||||
strictEqual( form.data( "ui-form-reset-instances" ), undefined,
|
||||
assert.deepEqual( $.ui.testWidget.refreshed, [], "No widgets are refreshed after destroy" );
|
||||
assert.strictEqual( form.data( "ui-form-reset-instances" ), undefined,
|
||||
"Form data is removed when the last widget instance is destroyed" );
|
||||
start();
|
||||
ready();
|
||||
} );
|
||||
} );
|
||||
form[ 0 ].reset();
|
||||
|
Loading…
Reference in New Issue
Block a user