]> source.dussan.org Git - jquery-ui.git/commitdiff
Datepicker: Fixed current instance memory leak and added unit testcases
authorjigar gala <jigar.gala140291@gmail.com>
Wed, 31 Jan 2018 19:45:58 +0000 (01:15 +0530)
committerFelix Nagel <fnagel@users.noreply.github.com>
Mon, 23 Mar 2020 20:49:23 +0000 (21:49 +0100)
tests/unit/datepicker/methods.js
ui/widgets/datepicker.js

index 4fc0c84ec74351aa2a70a136e7ad2af80b62f269..8729c5606f99992132f5c954b7c161680487d7f9 100644 (file)
@@ -8,9 +8,18 @@ define( [
 QUnit.module( "datepicker: methods" );
 
 QUnit.test( "destroy", function( assert ) {
-       assert.expect( 33 );
+       assert.expect( 35 );
        var inl,
-               inp = testHelper.init( "#inp" );
+               inp = testHelper.init( "#inp" ),
+               dp = $( "#ui-datepicker-div" );
+
+       // Destroy and clear active reference
+       inp.datepicker( "show" );
+       assert.equal( dp.css( "display" ), "block", "Datepicker - visible" );
+       inp.datepicker( "hide" ).datepicker( "destroy" );
+       assert.ok( $.datepicker._curInst == null, "Datepicker - destroyed and cleared reference" );
+
+       inp = testHelper.init( "#inp" );
        assert.ok( inp.is( ".hasDatepicker" ), "Default - marker class set" );
        assert.ok( $.data( inp[ 0 ], testHelper.PROP_NAME ), "Default - instance present" );
        assert.ok( inp.next().is( "#alt" ), "Default - button absent" );
index 5e6321e1d440a4250335b7e31e817d764db32c8e..441170c97786e53c0115b5f63273ddabc0401518 100644 (file)
@@ -408,6 +408,7 @@ $.extend( Datepicker.prototype, {
 
                if ( datepicker_instActive === inst ) {
                        datepicker_instActive = null;
+                       this._curInst = null;
                }
        },