Skip to content

Commit 5962e7b

Browse files
committed
Use navigate helper in full iframe load tests
1 parent f87feba commit 5962e7b

File tree

1 file changed

+41
-48
lines changed

1 file changed

+41
-48
lines changed

test/unit/pjax.js

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -303,70 +303,63 @@ if ($.support.pjax) {
303303
})
304304
})
305305

306-
asyncTest("missing fragment falls back to full load", function() {
307-
var frame = this.frame
306+
asyncTest("missing fragment falls back to full load", 2, function() {
307+
var iframe = this.iframe
308308

309-
frame.$.pjax({
310-
url: "hello.html?layout=true",
311-
fragment: "#missing",
312-
container: "#main"
309+
navigate(this.frame)
310+
.pjax({ url: "hello.html?layout=true", fragment: "#missing", container: "#main" }, function() {
311+
return new PoorMansPromise(function(resolve) {
312+
iframe.onload = function() { resolve(this.contentWindow) }
313+
}).then(function(frame) {
314+
equal(frame.$("#main p").html(), "Hello!")
315+
equal(frame.location.pathname, "/hello.html")
316+
})
313317
})
314-
315-
this.iframe.onload = function() {
316-
equal(frame.$("#main p").html(), "Hello!")
317-
equal(frame.location.pathname, "/hello.html")
318-
start()
319-
}
320318
})
321319

322-
asyncTest("missing data falls back to full load", function() {
323-
var frame = this.frame
320+
asyncTest("missing data falls back to full load", 2, function() {
321+
var iframe = this.iframe
324322

325-
frame.$.pjax({
326-
url: "empty.html",
327-
container: "#main"
323+
navigate(this.frame)
324+
.pjax({ url: "empty.html", container: "#main" }, function() {
325+
return new PoorMansPromise(function(resolve) {
326+
iframe.onload = function() { resolve(this.contentWindow) }
327+
}).then(function(frame) {
328+
equal(frame.$("#main").html().trim(), "")
329+
equal(frame.location.pathname, "/empty.html")
330+
})
328331
})
329-
330-
this.iframe.onload = function() {
331-
equal(frame.$("#main").html().trim(), "")
332-
equal(frame.location.pathname, "/empty.html")
333-
start()
334-
}
335332
})
336333

337-
asyncTest("full html page falls back to full load", function() {
338-
var frame = this.frame
334+
asyncTest("full html page falls back to full load", 2, function() {
335+
var iframe = this.iframe
339336

340-
frame.$.pjax({
341-
url: "hello.html?layout=true",
342-
container: "#main"
337+
navigate(this.frame)
338+
.pjax({ url: "hello.html?layout=true", container: "#main" }, function() {
339+
return new PoorMansPromise(function(resolve) {
340+
iframe.onload = function() { resolve(this.contentWindow) }
341+
}).then(function(frame) {
342+
equal(frame.$("#main p").html(), "Hello!")
343+
equal(frame.location.pathname, "/hello.html")
344+
})
343345
})
344-
345-
this.iframe.onload = function() {
346-
equal(frame.$("#main p").html(), "Hello!")
347-
equal(frame.location.pathname, "/hello.html")
348-
start()
349-
}
350346
})
351347

352-
asyncTest("header version mismatch does a full load", function() {
353-
var frame = this.frame
354-
355-
frame.$.pjax.defaults.version = 'v2'
348+
asyncTest("header version mismatch does a full load", 2, function() {
349+
var iframe = this.iframe
350+
this.frame.$.pjax.defaults.version = "v2"
356351

357-
frame.$.pjax({
358-
url: "hello.html",
359-
container: "#main"
352+
navigate(this.frame)
353+
.pjax({ url: "hello.html", container: "#main" }, function() {
354+
return new PoorMansPromise(function(resolve) {
355+
iframe.onload = function() { resolve(this.contentWindow) }
356+
}).then(function(frame) {
357+
equal(frame.$("#main p").html(), "Hello!")
358+
equal(frame.location.pathname, "/hello.html")
359+
})
360360
})
361-
362-
this.iframe.onload = function() {
363-
equal(frame.$("#main p").html(), "Hello!")
364-
equal(frame.location.pathname, "/hello.html")
365-
start()
366-
}
367361
})
368362

369-
370363
asyncTest("triggers pjax:start event from container", function() {
371364
var frame = this.frame
372365

0 commit comments

Comments
 (0)