@@ -536,6 +536,28 @@ if ($.support.pjax) {
536536 } )
537537 } )
538538
539+ asyncTest ( "triggers pjax:beforeReplace event from container" , function ( ) {
540+ var frame = this . frame ,
541+ beforeContent = 'foo'
542+
543+ frame . $ ( "#main" )
544+ . text ( beforeContent )
545+ . on ( "pjax:beforeReplace" , function ( event , contents , options ) {
546+ ok ( event )
547+ ok ( contents )
548+ equal ( $ ( event . target ) . text ( ) , beforeContent )
549+ equal ( options . url , "hello.html" )
550+ } )
551+ frame . $ ( "#main" ) . on ( "pjax:success" , function ( event ) {
552+ notEqual ( $ ( event . target ) . text ( ) , beforeContent )
553+ start ( )
554+ } )
555+
556+ frame . $ . pjax ( {
557+ url : "hello.html" ,
558+ container : "#main"
559+ } )
560+ } )
539561
540562 asyncTest ( "triggers pjax:success event from container" , function ( ) {
541563 var frame = this . frame
@@ -828,6 +850,34 @@ if ($.support.pjax) {
828850 } )
829851 } )
830852
853+ asyncTest ( "popstate triggers pjax:beforeReplace event" , function ( ) {
854+ var frame = this . frame ,
855+ originalContent = $ ( frame ) . html ( )
856+
857+ equal ( frame . location . pathname , "/home.html" )
858+
859+ frame . $ ( '#main' ) . on ( "pjax:complete" , function ( ) {
860+ equal ( frame . location . pathname , "/hello.html" )
861+ ok ( frame . history . length > 1 )
862+
863+ frame . $ ( '#main' ) . on ( 'pjax:beforeReplace' , function ( event , contents , options ) {
864+ ok ( event )
865+ ok ( contents )
866+ equal ( frame . location . pathname , "/home.html" )
867+ // Remember: the content hasn't yet been replaced.
868+ notEqual ( $ ( event . target ) . html ( ) , originalContent )
869+ start ( )
870+ } )
871+
872+ goBack ( frame , function ( ) { } )
873+ } )
874+
875+ frame . $ . pjax ( {
876+ url : "hello.html" ,
877+ container : "#main"
878+ } )
879+ } )
880+
831881 // Test is fragile
832882 asyncTest ( "no initial pjax:popstate event" , function ( ) {
833883 var frame = this . frame
0 commit comments