Skip to content

Commit 4384497

Browse files
committed
Add a test that shows that #309 is fixed
1 parent b92f80e commit 4384497

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/unit/pjax.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,4 +1011,44 @@ if ($.support.pjax) {
10111011
ok(frame.$.pjax.state.id)
10121012
oldId = frame.$.pjax.state.id
10131013
})
1014+
1015+
asyncTest("handles going back to pjaxed state after reloading a fragment navigation", function() {
1016+
var iframe = this.iframe
1017+
var frame = this.frame
1018+
1019+
// Get some pjax state in the history.
1020+
frame.$.pjax({
1021+
url: "hello.html",
1022+
container: "#main",
1023+
})
1024+
frame.$("#main").on("pjax:complete", function() {
1025+
var state = frame.history.state
1026+
ok(frame.history.state)
1027+
ok(frame.$.pjax.state)
1028+
1029+
// Navigate to a fragment, which will result in a new history entry with
1030+
// no state object. $.pjax.state remains unchanged however.
1031+
iframe.src = frame.location.href + '#foo'
1032+
ok(!frame.history.state)
1033+
ok(frame.$.pjax.state)
1034+
1035+
// Reload the frame. This will clear out $.pjax.state.
1036+
frame.location.reload()
1037+
$(iframe).one("load", function() {
1038+
ok(!frame.history.state)
1039+
ok(!frame.$.pjax.state)
1040+
1041+
// Go back to #main. We'll get a popstate event with a pjax state
1042+
// object attached from the initial pjax navigation, even though
1043+
// $.pjax.state is null.
1044+
window.iframeLoad = function() {
1045+
ok(frame.history.state)
1046+
ok(frame.$.pjax.state)
1047+
equal(frame.$.pjax.state.id, state.id)
1048+
start()
1049+
}
1050+
frame.history.back()
1051+
})
1052+
})
1053+
})
10141054
}

0 commit comments

Comments
 (0)