1
1
describe ( 'browser' , function ( ) {
2
2
3
- var browser , fakeWindow , xhr , logs , scripts , setTimeoutQueue ;
3
+ var browser , fakeWindow , xhr , logs , scripts , removedScripts , setTimeoutQueue ;
4
4
5
5
function fakeSetTimeout ( fn ) {
6
6
setTimeoutQueue . push ( fn ) ;
@@ -17,13 +17,15 @@ describe('browser', function(){
17
17
beforeEach ( function ( ) {
18
18
setTimeoutQueue = [ ] ;
19
19
scripts = [ ] ;
20
+ removedScripts = [ ] ;
20
21
xhr = null ;
21
22
fakeWindow = {
22
23
location : { href :"http://server" } ,
23
24
setTimeout : fakeSetTimeout
24
25
} ;
25
26
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 ) ; } } ] ;
27
29
28
30
var FakeXhr = function ( ) {
29
31
xhr = this ;
@@ -87,15 +89,13 @@ describe('browser', function(){
87
89
expect ( callback ) . not . toHaveBeenCalled ( ) ;
88
90
expect ( scripts . length ) . toEqual ( 1 ) ;
89
91
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=' ) ;
94
93
expect ( url [ 0 ] ) . toEqual ( 'http://example.org/path' ) ;
95
94
expect ( typeof fakeWindow [ url [ 1 ] ] ) . toEqual ( $function ) ;
96
95
fakeWindow [ url [ 1 ] ] ( 'data' ) ;
97
96
expect ( callback ) . toHaveBeenCalled ( ) ;
98
- expect ( log ) . toEqual ( 'remove();200:data;' ) ;
97
+ expect ( log ) . toEqual ( '200:data;' ) ;
98
+ expect ( scripts ) . toEqual ( removedScripts ) ;
99
99
expect ( fakeWindow [ url [ 1 ] ] ) . toBeUndefined ( ) ;
100
100
} ) ;
101
101
} ) ;
0 commit comments