Skip to content

Commit c70cfe3

Browse files
committed
Test that URL only changes on PJAX success
In preparation for the next commit which will delay pushState until pjax success, here we remove assertions that the address bar changes immediately, and add a failing test of the desired behaviour.
1 parent c4945b6 commit c70cfe3

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

test/unit/pjax.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,6 @@ if ($.support.pjax) {
322322
data: { foo: 1, bar: 2 },
323323
container: "#main"
324324
})
325-
326-
// URL is set immediately
327-
equal(frame.location.pathname, "/env.html")
328-
equal(frame.location.search, "?foo=1&bar=2")
329325
})
330326

331327
asyncTest("GET data is merged into query string", function() {
@@ -345,10 +341,6 @@ if ($.support.pjax) {
345341
data: { bar: 2 },
346342
container: "#main"
347343
})
348-
349-
// URL is set immediately
350-
equal(frame.location.pathname, "/env.html")
351-
equal(frame.location.search, "?foo=1&bar=2")
352344
})
353345

354346
asyncTest("mixed containers", function() {
@@ -745,9 +737,6 @@ if ($.support.pjax) {
745737
container: "#main"
746738
})
747739

748-
equal(frame.location.pathname, "/timeout.html")
749-
equal(frame.location.hash, "#hello")
750-
751740
this.iframe.onload = function() {
752741
equal(frame.$("#main p").html(), "SLOW DOWN!")
753742
equal(frame.location.pathname, "/timeout.html")
@@ -817,7 +806,7 @@ if ($.support.pjax) {
817806
var frame = this.frame
818807

819808
frame.$("#main").on("pjax:complete", function() {
820-
equal(frame.location.pathname, "/boom.html")
809+
equal(frame.location.pathname, "/home.html")
821810
start()
822811
})
823812
frame.$("#main").on("pjax:error", function(event, xhr) {
@@ -835,6 +824,26 @@ if ($.support.pjax) {
835824
})
836825
})
837826

827+
asyncTest("address bar only updates on success", function() {
828+
var frame = this.frame
829+
830+
equal(frame.location.pathname, "/home.html")
831+
832+
frame.$("#main").on('pjax:send', function() {
833+
equal(frame.location.pathname, "/home.html")
834+
})
835+
836+
frame.$("#main").on('pjax:end', function() {
837+
equal(frame.location.pathname, "/hello.html")
838+
start()
839+
})
840+
841+
frame.$.pjax({
842+
url: "hello.html",
843+
container: "#main"
844+
})
845+
})
846+
838847
function goBack(frame, callback) {
839848
setTimeout(function() {
840849
frame.$("#main").one("pjax:end", callback)

test/unit/pjax_fallback.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,8 @@ asyncTest("scrolls to anchor at top page"+s, function() {
139139
container: "#main"
140140
})
141141

142-
if (disabled) {
143-
equal(frame.location.pathname, "/home.html")
144-
equal(frame.location.hash, "")
145-
} else {
146-
equal(frame.location.pathname, "/anchor.html")
147-
equal(frame.location.hash, "#top")
148-
}
142+
equal(frame.location.pathname, "/home.html")
143+
equal(frame.location.hash, "")
149144
})
150145

151146
asyncTest("empty anchor doesn't scroll page"+s, function() {

0 commit comments

Comments
 (0)