11describe ( 'browser' , function ( ) {
22
3- var browser , fakeWindow , xhr , logs , scripts , setTimeoutQueue ;
3+ var browser , fakeWindow , xhr , logs , scripts , removedScripts , setTimeoutQueue ;
44
55 function fakeSetTimeout ( fn ) {
66 setTimeoutQueue . push ( fn ) ;
@@ -17,13 +17,15 @@ describe('browser', function(){
1717 beforeEach ( function ( ) {
1818 setTimeoutQueue = [ ] ;
1919 scripts = [ ] ;
20+ removedScripts = [ ] ;
2021 xhr = null ;
2122 fakeWindow = {
2223 location : { href :"http://server" } ,
2324 setTimeout : fakeSetTimeout
2425 } ;
2526
26- var fakeBody = { append : function ( node ) { scripts . push ( node ) ; } } ;
27+ var fakeBody = [ { appendChild : function ( node ) { scripts . push ( node ) ; } ,
28+ removeChild : function ( node ) { removedScripts . push ( node ) ; } } ] ;
2729
2830 var FakeXhr = function ( ) {
2931 xhr = this ;
@@ -87,15 +89,13 @@ describe('browser', function(){
8789 expect ( callback ) . not . toHaveBeenCalled ( ) ;
8890 expect ( scripts . length ) . toEqual ( 1 ) ;
8991 var script = scripts [ 0 ] ;
90- script . remove = function ( ) {
91- log += 'remove();' ;
92- } ;
93- var url = script . attr ( 'src' ) . split ( '?cb=' ) ;
92+ var url = script . src . split ( '?cb=' ) ;
9493 expect ( url [ 0 ] ) . toEqual ( 'http://example.org/path' ) ;
9594 expect ( typeof fakeWindow [ url [ 1 ] ] ) . toEqual ( $function ) ;
9695 fakeWindow [ url [ 1 ] ] ( 'data' ) ;
9796 expect ( callback ) . toHaveBeenCalled ( ) ;
98- expect ( log ) . toEqual ( 'remove();200:data;' ) ;
97+ expect ( log ) . toEqual ( '200:data;' ) ;
98+ expect ( scripts ) . toEqual ( removedScripts ) ;
9999 expect ( fakeWindow [ url [ 1 ] ] ) . toBeUndefined ( ) ;
100100 } ) ;
101101 } ) ;
0 commit comments