@@ -512,6 +512,41 @@ describe('form', function() {
512512 expect ( doc . find ( 'div' ) . hasClass ( 'ng-invalid-maxlength' ) ) . toBe ( false ) ;
513513 } ) ;
514514
515+ it ( 'should deregister a input that is $pending when it is removed from DOM' , function ( ) {
516+ doc = jqLite (
517+ '<form name="parent">' +
518+ '<div class="ng-form" name="child">' +
519+ '<input ng-if="inputPresent" ng-model="modelA" name="inputA">' +
520+ '</div>' +
521+ '</form>' ) ;
522+ $compile ( doc ) ( scope ) ;
523+ scope . $apply ( 'inputPresent = true' ) ;
524+
525+ var parent = scope . parent ;
526+ var child = scope . child ;
527+ var input = child . inputA ;
528+
529+ scope . $apply ( child . inputA . $setValidity ( 'fake' , undefined ) ) ;
530+
531+ expect ( parent ) . toBeDefined ( ) ;
532+ expect ( child ) . toBeDefined ( ) ;
533+
534+ expect ( parent . $pending . fake ) . toEqual ( [ child ] ) ;
535+ expect ( child . $pending . fake ) . toEqual ( [ input ] ) ;
536+
537+ expect ( doc . hasClass ( 'ng-pending' ) ) . toBe ( true ) ;
538+ expect ( doc . find ( 'div' ) . hasClass ( 'ng-pending' ) ) . toBe ( true ) ;
539+
540+ //remove child input
541+ scope . $apply ( 'inputPresent = false' ) ;
542+
543+ expect ( parent . $pending ) . toBeUndefined ( ) ;
544+ expect ( child . $pending ) . toBeUndefined ( ) ;
545+
546+ expect ( doc . hasClass ( 'ng-pending' ) ) . toBe ( false ) ;
547+ expect ( doc . find ( 'div' ) . hasClass ( 'ng-pending' ) ) . toBe ( false ) ;
548+ } ) ;
549+
515550 it ( 'should leave the parent form invalid when deregister a removed input' , function ( ) {
516551 doc = jqLite (
517552 '<form name="parent">' +
0 commit comments