Skip to content

Commit

Permalink
Untangle "evals scripts" test
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Apr 2, 2015
1 parent e765fd8 commit f87feba
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 33 deletions.
6 changes: 1 addition & 5 deletions test/evaled.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
window.evaledSrcScriptNum = window.evaledSrcScriptNum || 0
window.evaledSrcScriptNum++

if (window.evaledSrcScriptNum === 2)
window.evaledScriptLoaded()
window.externalScriptLoaded()
51 changes: 25 additions & 26 deletions test/unit/pjax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
})
})

Expand Down
4 changes: 2 additions & 2 deletions test/views/scripts.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p>Got some script tags here</p>
<script type="text/javascript" src="/test/evaled.js"></script>
<script src="/test/evaled.js"></script>
<script type="text/javascript" src="/test/evaled.js?1"></script>
<script src="/test/evaled.js?2"></script>
<script type="text/javascript">
window.evaledInlineLog = window.evaledInlineLog || []
window.evaledInlineLog.push('<%= params[:name] %>')
Expand Down

0 comments on commit f87feba

Please sign in to comment.