diff options
| author | Misko Hevery | 2011-11-04 12:33:01 -0700 | 
|---|---|---|
| committer | Misko Hevery | 2011-11-14 20:31:14 -0800 | 
| commit | a87f2fb9e4d65ac5d260e914b5e31aa0e0f47b2c (patch) | |
| tree | 93e69475affd24ef5b16c68e47d1476bc37787a7 /test/testabilityPatch.js | |
| parent | c27aba4354c69c4a67fab587a59a8079cc9edc91 (diff) | |
| download | angular.js-a87f2fb9e4d65ac5d260e914b5e31aa0e0f47b2c.tar.bz2 | |
refactor(mock): moved mocks into its own module
Diffstat (limited to 'test/testabilityPatch.js')
| -rw-r--r-- | test/testabilityPatch.js | 131 | 
1 files changed, 16 insertions, 115 deletions
| diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 96deac5a..b2bcb519 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -9,46 +9,10 @@  _jQuery.event.special.change = undefined; -if (window.jstestdriver) { -  window.jstd = jstestdriver; -  window.dump = function dump() { -    var args = []; -    forEach(arguments, function(arg){ -      if (isElement(arg)) { -        arg = sortedHtml(arg); -      } else if (isObject(arg)) { -        if (isFunction(arg.$eval) && isFunction(arg.$apply)) { -          arg = dumpScope(arg); -        } else { -          arg = toJson(arg, true); -        } -      } -      args.push(arg); -    }); -    jstd.console.log.apply(jstd.console, args); -  }; -} - -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); -} - -publishExternalAPI(angular) +publishExternalAPI(angular); +bindJQuery();  beforeEach(function() { -  publishExternalAPI(angular) +  publishExternalAPI(angular);    // workaround for IE bug https://plus.google.com/104744871076396904202/posts/Kqjuj6RSbbT    // IE overwrite window.jQuery with undefined because of empty jQuery var statement, so we have to @@ -63,43 +27,20 @@ beforeEach(function() {    // reset to jQuery or default to us.    bindJQuery();    jqLite(document.body).html(''); - -  this.addMatchers({ -    toHaveClass: function(clazz) { -      this.message = function() { -        return "Expected '" + sortedHtml(this.actual) + "' to have class '" + clazz + "'."; -      }; -      return this.actual.hasClass ? -              this.actual.hasClass(clazz) : -              jqLite(this.actual).hasClass(clazz); -    } -  }); -  }); -function inject(){ -  var blockFns = sliceArgs(arguments); -  return function(){ -    var spec = this; -    spec.$injector = spec.$injector || angular.injector('NG', 'NG_MOCK'); -    angular.forEach(blockFns, function(fn){ -      spec.$injector.invoke(spec, fn); -    }); -  }; -} - - -afterEach(inject(function($rootScope, $log) { -  // release the injector -  dealoc($rootScope); - -  // check $log mock -  $log.assertEmpty && $log.assertEmpty(); +afterEach(function() { +  if (this.$injector) { +    var $rootScope = this.$injector('$rootScope'); +    var $log = this.$injector('$log'); +    // release the injector +    dealoc($rootScope); -  clearJqCache(); -})); +    // check $log mock +    $log.assertEmpty && $log.assertEmpty(); +  } -function clearJqCache() { +  // complain about uncleared jqCache references    var count = 0;    forEachSorted(jqCache, function(value, key){      count ++; @@ -115,15 +56,8 @@ function clearJqCache() {    if (count) {      fail('Found jqCache references that were not deallocated!');    } -} - -function nakedExpect(obj) { -  return expect(angular.fromJson(angular.toJson(obj))); -} +}); -function childNode(element, index) { -  return jqLite(element[0].childNodes[index]); -}  function dealoc(obj) {    if (obj) { @@ -240,43 +174,10 @@ function isCssVisible(node) {  }  function assertHidden(node) { -  assertFalse("Node should be hidden but vas visible: " + sortedHtml(node), isCssVisible(node)); +  assertFalse("Node should be hidden but vas visible: " + angular.mock.dump(node), isCssVisible(node));  }  function assertVisible(node) { -  assertTrue("Node should be visible but vas hidden: " + sortedHtml(node), isCssVisible(node)); -} - -function assertJsonEquals(expected, actual) { -  assertEquals(toJson(expected), toJson(actual)); -} - -function assertUndefined(value) { -  assertEquals('undefined', typeof value); +  assertTrue("Node should be visible but vas hidden: " + angular.mock.dump(node), isCssVisible(node));  } -function assertDefined(value) { -  assertTrue(toJson(value), !!value); -} - -function assertThrows(error, fn){ -  var exception = null; -  try { -    fn(); -  } catch(e) { -    exception = e; -  } -  if (!exception) { -    fail("Expecting exception, none thrown"); -  } -  assertEquals(error, exception); -} - -window.log = noop; -window.error = noop; - -function rethrow(e) { -  if(e) { -    throw e; -  } -} | 
