mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-24 03:55:49 +08:00
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.
This commit is contained in:
@@ -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]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user