diff --git a/test/evaled.js b/test/evaled.js index 2ce436e9..20a491ef 100644 --- a/test/evaled.js +++ b/test/evaled.js @@ -1,5 +1 @@ -window.evaledSrcScriptNum = window.evaledSrcScriptNum || 0 -window.evaledSrcScriptNum++ - -if (window.evaledSrcScriptNum === 2) - window.evaledScriptLoaded() +window.externalScriptLoaded() diff --git a/test/unit/pjax.js b/test/unit/pjax.js index c9728ecc..9f2c698c 100644 --- a/test/unit/pjax.js +++ b/test/unit/pjax.js @@ -76,36 +76,35 @@ if ($.support.pjax) { }) }) - asyncTest("evals scripts", function() { - var frame = this.frame + asyncTest("evals scripts", 7, function() { + var externalLoadedCount = 0 + this.frame.externalScriptLoaded = function() { + externalLoadedCount++ + } - frame.evaledScriptLoaded = function() { - equal(frame.evaledSrcScriptNum, 2) + navigate(this.frame) + .pjax({ url: "scripts.html?name=one", container: "#main" }, function(frame) { deepEqual(frame.evaledInlineLog, ["one"]) - - frame.$.pjax({ - url: "scripts.html?name=two", - container: "#main" + equal(externalLoadedCount, 0) + return new PoorMansPromise(function(resolve) { + setTimeout(resolve, 100) + }).then(function() { + equal(externalLoadedCount, 2, "expected scripts to have loaded") }) - - frame.$("#main").one("pjax:end", function() { - deepEqual(frame.evaledInlineLog, ["one", "two"]) - - goBack(frame, function() { - deepEqual(frame.evaledInlineLog, ["one", "two", "one"]) - - goForward(frame, function() { - deepEqual(frame.evaledInlineLog, ["one", "two", "one", "two"]) - equal(frame.evaledSrcScriptNum, 2) - start() - }) - }) + }) + .pjax({ url: "scripts.html?name=two", container: "#main" }, function(frame) { + deepEqual(frame.evaledInlineLog, ["one", "two"]) + }) + .back(-1, function(frame) { + deepEqual(frame.evaledInlineLog, ["one", "two", "one"]) + }) + .back(+1, function(frame) { + deepEqual(frame.evaledInlineLog, ["one", "two", "one", "two"]) + return new PoorMansPromise(function(resolve) { + setTimeout(resolve, 100) + }).then(function() { + equal(externalLoadedCount, 2, "expected no extra scripts to load") }) - } - - frame.$.pjax({ - url: "scripts.html?name=one", - container: "#main" }) }) diff --git a/test/views/scripts.erb b/test/views/scripts.erb index 73d69b50..2e4ca107 100644 --- a/test/views/scripts.erb +++ b/test/views/scripts.erb @@ -1,6 +1,6 @@
Got some script tags here
- - + +