aboutsummaryrefslogtreecommitdiffstats
path: root/test/directive/inputSpec.js
diff options
context:
space:
mode:
authorIgor Minar2012-03-13 14:56:52 -0700
committerIgor Minar2012-03-13 16:05:52 -0700
commit4806d28a29ae5c3f83d8f97c11e692ca2313c9ab (patch)
tree914f4e3b2ecdd2f4bccd89bea820da3b2fd54b2d /test/directive/inputSpec.js
parent089c0f8b0e64f00e2629de07f35af03f01c34686 (diff)
downloadangular.js-4806d28a29ae5c3f83d8f97c11e692ca2313c9ab.tar.bz2
fix(forms): remove control.$form and use nullFormCtrl
Diffstat (limited to 'test/directive/inputSpec.js')
-rw-r--r--test/directive/inputSpec.js52
1 files changed, 29 insertions, 23 deletions
diff --git a/test/directive/inputSpec.js b/test/directive/inputSpec.js
index d68f6c54..4bdba36a 100644
--- a/test/directive/inputSpec.js
+++ b/test/directive/inputSpec.js
@@ -1,15 +1,24 @@
'use strict';
describe('NgModelController', function() {
- var ctrl, scope, ngModelAccessor;
+ var ctrl, scope, ngModelAccessor, element, parentFormCtrl;
beforeEach(inject(function($rootScope, $controller) {
var attrs = {name: 'testAlias'};
+ parentFormCtrl = {
+ $setValidity: jasmine.createSpy('$setValidity'),
+ $setDirty: jasmine.createSpy('$setDirty')
+ }
+
+ element = jqLite('<form><input></form>');
+ element.data('$formController', parentFormCtrl);
+
scope = $rootScope;
ngModelAccessor = jasmine.createSpy('ngModel accessor');
- ctrl = $controller(NgModelController, {$scope: scope, ngModel: ngModelAccessor, $attrs: attrs});
-
+ ctrl = $controller(NgModelController, {
+ $scope: scope, $element: element.find('input'), ngModel: ngModelAccessor, $attrs: attrs
+ });
// mock accessor (locals)
ngModelAccessor.andCallFake(function(val) {
if (isDefined(val)) scope.value = val;
@@ -18,6 +27,11 @@ describe('NgModelController', function() {
}));
+ afterEach(function() {
+ dealoc(element);
+ });
+
+
it('should init the properties', function() {
expect(ctrl.$dirty).toBe(false);
expect(ctrl.$pristine).toBe(true);
@@ -37,15 +51,13 @@ describe('NgModelController', function() {
describe('setValidity', function() {
it('should propagate invalid to the parent form only when valid', function() {
- var spy = jasmine.createSpy('setValidity');
- ctrl.$form = {$setValidity: spy};
-
+ expect(parentFormCtrl.$setValidity).not.toHaveBeenCalled();
ctrl.$setValidity('ERROR', false);
- expect(spy).toHaveBeenCalledOnceWith('ERROR', false, ctrl);
+ expect(parentFormCtrl.$setValidity).toHaveBeenCalledOnceWith('ERROR', false, ctrl);
- spy.reset();
+ parentFormCtrl.$setValidity.reset();
ctrl.$setValidity('ERROR', false);
- expect(spy).not.toHaveBeenCalled();
+ expect(parentFormCtrl.$setValidity).not.toHaveBeenCalled();
});
@@ -78,17 +90,14 @@ describe('NgModelController', function() {
it('should emit $valid only when $invalid', function() {
- var spy = jasmine.createSpy('setValidity');
- ctrl.$form = {$setValidity: spy};
-
ctrl.$setValidity('ERROR', true);
- expect(spy).not.toHaveBeenCalled();
+ expect(parentFormCtrl.$setValidity).not.toHaveBeenCalled();
ctrl.$setValidity('ERROR', false);
- expect(spy).toHaveBeenCalledOnceWith('ERROR', false, ctrl);
- spy.reset();
+ expect(parentFormCtrl.$setValidity).toHaveBeenCalledOnceWith('ERROR', false, ctrl);
+ parentFormCtrl.$setValidity.reset();
ctrl.$setValidity('ERROR', true);
- expect(spy).toHaveBeenCalledOnceWith('ERROR', true, ctrl);
+ expect(parentFormCtrl.$setValidity).toHaveBeenCalledOnceWith('ERROR', true, ctrl);
});
});
@@ -147,20 +156,17 @@ describe('NgModelController', function() {
});
- it('should call parentForm.setDirty only when pristine', function() {
- var spy = jasmine.createSpy('setDirty');
- ctrl.$form = {$setDirty: spy};
-
+ it('should call parentForm.$setDirty only when pristine', function() {
ctrl.$setViewValue('');
expect(ctrl.$pristine).toBe(false);
expect(ctrl.$dirty).toBe(true);
- expect(spy).toHaveBeenCalledOnce();
+ expect(parentFormCtrl.$setDirty).toHaveBeenCalledOnce();
- spy.reset();
+ parentFormCtrl.$setDirty.reset();
ctrl.$setViewValue('');
expect(ctrl.$pristine).toBe(false);
expect(ctrl.$dirty).toBe(true);
- expect(spy).not.toHaveBeenCalled();
+ expect(parentFormCtrl.$setDirty).not.toHaveBeenCalled();
});
});