aboutsummaryrefslogtreecommitdiffstats
path: root/test/ValidatorsTest.js
diff options
context:
space:
mode:
authorMisko Hevery2010-04-16 14:01:29 -0700
committerMisko Hevery2010-04-16 14:01:29 -0700
commitdeb86fe357a901889bc4289087f0b9e69cb8a302 (patch)
treefce4db8501a6c24430d611c95a4aa001119c7b89 /test/ValidatorsTest.js
parent70e401ef100614295fc808e32f0142f07c315461 (diff)
downloadangular.js-deb86fe357a901889bc4289087f0b9e69cb8a302.tar.bz2
lots of small fixes
Diffstat (limited to 'test/ValidatorsTest.js')
-rw-r--r--test/ValidatorsTest.js34
1 files changed, 25 insertions, 9 deletions
diff --git a/test/ValidatorsTest.js b/test/ValidatorsTest.js
index 49416ae4..b2403eab 100644
--- a/test/ValidatorsTest.js
+++ b/test/ValidatorsTest.js
@@ -88,17 +88,16 @@ describe('Validator:asynchronous', function(){
var value, fn;
beforeEach(function(){
- var invalidWidgets = [];
- invalidWidgets.markInvalid = function(element){
- invalidWidgets.push(element);
- };
+ var invalidWidgets = angularService('$invalidWidgets')();
value = null;
fn = null;
self = {
$element:jqLite('<input />'),
$invalidWidgets:invalidWidgets,
- $updateView: noop
+ $eval: noop
};
+ self.$element.data('$validate', noop);
+ self.$root = self;
});
afterEach(function(){
@@ -122,14 +121,14 @@ describe('Validator:asynchronous', function(){
expect(input.hasClass('ng-input-indicator-wait')).toBeTruthy();
fn("myError");
expect(input.hasClass('ng-input-indicator-wait')).toBeFalsy();
- expect(input.attr('ng-validation-error')).toEqual("myError");
+ expect(input.attr(NG_VALIDATION_ERROR)).toEqual("myError");
scope.$element.remove();
});
it("should not make second request to same value", function(){
asynchronous.call(self, "kai", function(v,f){value=v; fn=f;});
expect(value).toEqual('kai');
- expect(self.$invalidWidgets[0][0]).toEqual(self.$element[0]);
+ expect(self.$invalidWidgets[0]).toEqual(self.$element);
var spy = jasmine.createSpy();
asynchronous.call(self, "kai", spy);
@@ -145,9 +144,26 @@ describe('Validator:asynchronous', function(){
asynchronous.call(self, "second", function(v,f){value=v; secondCb=f;});
firstCb();
- expect(jqLite(self.$element).hasClass('ng-input-indicator-wait')).toBeTruthy();
+ expect(self.$element.hasClass('ng-input-indicator-wait')).toBeTruthy();
secondCb();
- expect(jqLite(self.$element).hasClass('ng-input-indicator-wait')).toBeFalsy();
+ expect(self.$element.hasClass('ng-input-indicator-wait')).toBeFalsy();
});
+
+ it("should handle update function", function(){
+ var scope = angular.compile('<input name="name" ng-validate="asynchronous:asyncFn:updateFn"/>');
+ scope.asyncFn = jasmine.createSpy();
+ scope.updateFn = jasmine.createSpy();
+ scope.name = 'misko';
+ scope.$init();
+ scope.$eval();
+ expect(scope.asyncFn).wasCalledWith('misko', scope.asyncFn.mostRecentCall.args[1]);
+ assertTrue(scope.$element.hasClass('ng-input-indicator-wait'));
+ scope.asyncFn.mostRecentCall.args[1]('myError', {id: 1234, data:'data'});
+ assertFalse(scope.$element.hasClass('ng-input-indicator-wait'));
+ assertEquals('myError', scope.$element.attr('ng-validation-error'));
+ expect(scope.updateFn.mostRecentCall.args[0]).toEqual({id: 1234, data:'data'});
+ scope.$element.remove();
+ });
+
});