diff --git a/tests/jquery.testHelper.js b/tests/jquery.testHelper.js index a29befe6..ce9aaaa3 100644 --- a/tests/jquery.testHelper.js +++ b/tests/jquery.testHelper.js @@ -6,7 +6,7 @@ $.testHelper = { excludeFileProtocol: function(callback){ var message = "Tests require script reload and cannot be run via file: protocol"; - //NOTE alert tester that running the file locally will not work for these tests + if ( location.protocol == "file:" ) { test(message, function(){ ok(false, message); @@ -14,6 +14,21 @@ } else { callback(); } + }, + + reloadCounts: {}, + + reloadLib: function(libName){ + var lib = $("script[src$=" + libName + "]").clone(), + src = lib.attr('src'); + + if(this.reloadCounts[libName] === undefined) { + this.reloadCounts[libName] = 0; + } + + //NOTE append "cache breaker" to force reload + lib.attr('src', src + "?" + this.reloadCounts[libName]++); + $("body").append(lib); } }; })(jQuery); \ No newline at end of file diff --git a/tests/unit/support/support_core.js b/tests/unit/support/support_core.js index 0e5200f4..fb41bdd0 100644 --- a/tests/unit/support/support_core.js +++ b/tests/unit/support/support_core.js @@ -4,15 +4,8 @@ (function( $ ) { $.testHelper.excludeFileProtocol(function(){ - var reloadCount = 0, - lib = $("script[src$=support.js]"), - src = lib.attr('src'), - reloadLib = function(){ - //NOTE append "cache breaker" to force reload - lib.attr('src', src + "?" + reloadCount++); - $("body").append(lib); - }, - prependToFn = $.fn.prependTo; + var prependToFn = $.fn.prependTo, + libName = "jquery.mobile.support.js"; module("mobile.support", { teardown: function(){ @@ -35,7 +28,7 @@ history.pushState = function(){}; $.mobile.media = function(){ return true; }; - reloadLib(); + $.testHelper.reloadLib(libName); ok($.support.orientation); ok($.support.touch); @@ -48,7 +41,7 @@ delete window["orientation"]; delete document["ontouchend"]; - reloadLib(); + $.testHelper.reloadLib(libName); ok(!$.support.orientation); ok(!$.support.touch); @@ -68,13 +61,13 @@ test( "detects dynamic base tag when new base element added and base href updates", function(){ mockBaseCheck(location.protocol + '//' + location.host + location.pathname + "ui-dir/"); - reloadLib(); + $.testHelper.reloadLib(libName); ok($.support.dynamicBaseTag); }); test( "detects no dynamic base tag when new base element added and base href unchanged", function(){ mockBaseCheck('testurl'); - reloadLib(); + $.testHelper.reloadLib(libName); ok(!$.support.dynamicBaseTag); });