Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 833ea05

Browse files
committed
test(form): test if $pending inputs are correctly removed
It's a separate test because $pending behaves differently from $error - the property is completely removed when no pending inputs / forms are left.
1 parent ca5fcc6 commit 833ea05

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/ng/directive/formSpec.js

+35
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)