diff options
| author | Igor Minar | 2013-04-18 12:50:49 -0700 | 
|---|---|---|
| committer | Igor Minar | 2013-04-18 14:34:53 -0700 | 
| commit | 5da6b125a7447b4bbabb88b2d82b5634b55c3aea (patch) | |
| tree | d67bb5ce97dbed432b15ed9481f5055416437604 /test/testabilityPatch.js | |
| parent | 695c54c17b3299cd6170c45878b41cb46a577cd2 (diff) | |
| download | angular.js-5da6b125a7447b4bbabb88b2d82b5634b55c3aea.tar.bz2 | |
test(modules): fix module tests which got disabled by ngMobile
When ngMobile was merged in, we accidentaly included angular-scenario.js
in the test file set for modules. Loading this file overrode jasmine's
`it` and `describe` global functions which essentially disabled all of
~200 unit tests for wrapped modules.
This change refactors the code to run the wrapped module tests.
I had to extract browserTrigger from scenario runner in order to achieve
this without code duplication.
Diffstat (limited to 'test/testabilityPatch.js')
| -rw-r--r-- | test/testabilityPatch.js | 67 | 
1 files changed, 47 insertions, 20 deletions
diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index a4d4b46f..679294ee 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -6,25 +6,31 @@   * special event and changes it form 'change' to 'click/keydown' and   * few others. This horrible hack removes the special treatment   */ -_jQuery.event.special.change = undefined; +if (window._jQuery) _jQuery.event.special.change = undefined; + +if (window.bindJQuery) bindJQuery(); -bindJQuery();  beforeEach(function() { -  publishExternalAPI(angular); +  // all this stuff is not needed for module tests, where jqlite and publishExternalAPI and jqLite are not global vars +  if (window.publishExternalAPI) { +    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 +    // correct this, but only if we are not running in jqLite mode +    if (!_jqLiteMode && _jQuery !== jQuery) { +      jQuery = _jQuery; +    } -  // 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 -  // correct this, but only if we are not running in jqLite mode -  if (!_jqLiteMode && _jQuery !== jQuery) { -    jQuery = _jQuery; +    // This resets global id counter; +    uid = ['0', '0', '0']; + +    // reset to jQuery or default to us. +    bindJQuery();    } -  // This resets global id counter; -  uid = ['0', '0', '0']; -  // reset to jQuery or default to us. -  bindJQuery(); -  jqLite(document.body).html('').removeData(); +  angular.element(document.body).html('').removeData();  });  afterEach(function() { @@ -45,29 +51,50 @@ afterEach(function() {    // This line should be enabled as soon as this bug is fixed: http://bugs.jquery.com/ticket/11775    //var cache = jqLite.cache; -  var cache = JQLite.cache; +  var cache = angular.element.cache;    forEachSorted(cache, function(expando, key){ -    forEach(expando.data, function(value, key){ +    angular.forEach(expando.data, function(value, key){        count ++;        if (value.$element) {          dump('LEAK', key, value.$id, sortedHtml(value.$element));        } else { -        dump('LEAK', key, toJson(value)); +        dump('LEAK', key, angular.toJson(value));        }      });    });    if (count) {      throw new Error('Found jqCache references that were not deallocated! count: ' + count);    } + + +  // copied from Angular.js +  // we need these two methods here so that we can run module tests with wrapped angular.js +  function sortedKeys(obj) { +    var keys = []; +    for (var key in obj) { +      if (obj.hasOwnProperty(key)) { +        keys.push(key); +      } +    } +    return keys.sort(); +  } + +  function forEachSorted(obj, iterator, context) { +    var keys = sortedKeys(obj); +    for ( var i = 0; i < keys.length; i++) { +      iterator.call(context, obj[keys[i]], keys[i]); +    } +    return keys; +  }  });  function dealoc(obj) { -  var jqCache = jqLite.cache; +  var jqCache = angular.element.cache;    if (obj) { -    if (isElement(obj)) { -      cleanup(jqLite(obj)); +    if (angular.isElement(obj)) { +      cleanup(angular.element(obj));      } else {        for(var key in jqCache) {          var value = jqCache[key]; @@ -81,7 +108,7 @@ function dealoc(obj) {    function cleanup(element) {      element.unbind().removeData();      for ( var i = 0, children = element.contents() || []; i < children.length; i++) { -      cleanup(jqLite(children[i])); +      cleanup(angular.element(children[i]));      }    }  }  | 
