diff options
| author | Misko Hevery | 2011-09-08 13:56:29 -0700 | 
|---|---|---|
| committer | Igor Minar | 2011-10-11 11:01:45 -0700 | 
| commit | 4f78fd692c0ec51241476e6be9a4df06cd62fdd6 (patch) | |
| tree | 91f70bb89b9c095126fbc093f51cedbac5cb0c78 /test/testabilityPatch.js | |
| parent | df6d2ba3266de405ad6c2f270f24569355706e76 (diff) | |
| download | angular.js-4f78fd692c0ec51241476e6be9a4df06cd62fdd6.tar.bz2 | |
feat(forms): new and improved forms
Diffstat (limited to 'test/testabilityPatch.js')
| -rw-r--r-- | test/testabilityPatch.js | 70 | 
1 files changed, 51 insertions, 19 deletions
| diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 3b9d9208..41a6455c 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -11,13 +11,17 @@ _jQuery.event.special.change = undefined;  if (window.jstestdriver) {    window.jstd = jstestdriver; -  window.dump = function(){ +  window.dump = function dump(){      var args = [];      forEach(arguments, function(arg){        if (isElement(arg)) {          arg = sortedHtml(arg);        } else if (isObject(arg)) { -        arg = toJson(arg, true); +        if (arg.$eval == Scope.prototype.$eval) { +          arg = dumpScope(arg); +        } else { +          arg = toJson(arg, true); +        }        }        args.push(arg);      }); @@ -25,6 +29,23 @@ if (window.jstestdriver) {    };  } +function dumpScope(scope, offset) { +  offset = offset ||  '  '; +  var log = [offset + 'Scope(' + scope.$id + '): {']; +  for ( var key in scope ) { +    if (scope.hasOwnProperty(key) && !key.match(/^(\$|this)/)) { +      log.push('  ' + key + ': ' + toJson(scope[key])); +    } +  } +  var child = scope.$$childHead; +  while(child) { +    log.push(dumpScope(child, offset + '  ')); +    child = child.$$nextSibling; +  } +  log.push('}'); +  return log.join('\n' + offset); +} +  beforeEach(function(){    // This is to reset parsers global cache of expressions.    compileCache = {}; @@ -36,30 +57,41 @@ beforeEach(function(){      jQuery = _jQuery;    } +  // This resets global id counter; +  uid = ['0', '0', '0']; +    // reset to jQuery or default to us.    bindJQuery();    jqLite(document.body).html(''); -  this.addMatchers({ -    toBeInvalid: function(){ -      var element = jqLite(this.actual); -      var hasClass = element.hasClass('ng-validation-error'); -      var validationError = element.attr('ng-validation-error'); -      this.message = function(){ -        if (!hasClass) -          return "Expected class 'ng-validation-error' not found."; -        return "Expected an error message, but none was found."; -      }; -      return hasClass && validationError; -    }, -    toBeValid: function(){ +  function cssMatcher(presentClasses, absentClasses) { +    return function(){        var element = jqLite(this.actual); -      var hasClass = element.hasClass('ng-validation-error'); +      var present = true; +      var absent = false; + +      forEach(presentClasses.split(' '), function(className){ +        present = present && element.hasClass(className); +      }); + +      forEach(absentClasses.split(' '), function(className){ +        absent = absent || element.hasClass(className); +      }); +        this.message = function(){ -        return "Expected to not have class 'ng-validation-error' but found."; +        return "Expected to have " + presentClasses + +          (absentClasses ? (" and not have " + absentClasses + "" ) : "") + +          " but had " + element[0].className + ".";        }; -      return !hasClass; -    }, +      return present && !absent; +    }; +  } + +  this.addMatchers({ +    toBeInvalid: cssMatcher('ng-invalid', 'ng-valid'), +    toBeValid: cssMatcher('ng-valid', 'ng-invalid'), +    toBeDirty: cssMatcher('ng-dirty', 'ng-pristine'), +    toBePristine: cssMatcher('ng-pristine', 'ng-dirty'),      toEqualData: function(expected) {        return equals(this.actual, expected); | 
