diff options
| -rw-r--r-- | src/Browser.js | 6 | ||||
| -rw-r--r-- | test/BrowserSpecs.js | 14 | 
2 files changed, 9 insertions, 11 deletions
diff --git a/src/Browser.js b/src/Browser.js index 535396bd..4340ac4e 100644 --- a/src/Browser.js +++ b/src/Browser.js @@ -89,14 +89,12 @@ function Browser(window, document, body, XHR, $log) {      outstandingRequestCount ++;      if (lowercase(method) == 'json') {        var callbackId = ("angular_" + Math.random() + '_' + (idCounter++)).replace(/\d\./, ''); -      var script = jqLite(rawDocument.createElement('script')) -          .attr({type: 'text/javascript', src: url.replace('JSON_CALLBACK', callbackId)}); +      var script = self.addJs(url.replace('JSON_CALLBACK', callbackId));        window[callbackId] = function(data){          delete window[callbackId]; -        script.remove(); +        body[0].removeChild(script)          completeOutstandingRequest(callback, 200, data);        }; -      body.append(script);      } else {        var xhr = new XHR();        xhr.open(method, url, true); diff --git a/test/BrowserSpecs.js b/test/BrowserSpecs.js index f87e98f8..d6eb5697 100644 --- a/test/BrowserSpecs.js +++ b/test/BrowserSpecs.js @@ -1,6 +1,6 @@  describe('browser', function(){ -  var browser, fakeWindow, xhr, logs, scripts, setTimeoutQueue; +  var browser, fakeWindow, xhr, logs, scripts, removedScripts, setTimeoutQueue;    function fakeSetTimeout(fn) {      setTimeoutQueue.push(fn); @@ -17,13 +17,15 @@ describe('browser', function(){    beforeEach(function(){      setTimeoutQueue = [];      scripts = []; +    removedScripts = [];      xhr = null;      fakeWindow = {        location: {href:"http://server"},        setTimeout: fakeSetTimeout      }; -    var fakeBody = {append: function(node){scripts.push(node);}}; +    var fakeBody = [{appendChild: function(node){scripts.push(node);}, +                     removeChild: function(node){removedScripts.push(node);}}];      var FakeXhr = function(){        xhr = this; @@ -87,15 +89,13 @@ describe('browser', function(){          expect(callback).not.toHaveBeenCalled();          expect(scripts.length).toEqual(1);          var script = scripts[0]; -        script.remove = function(){ -          log += 'remove();'; -        }; -        var url = script.attr('src').split('?cb='); +        var url = script.src.split('?cb=');          expect(url[0]).toEqual('http://example.org/path');          expect(typeof fakeWindow[url[1]]).toEqual($function);          fakeWindow[url[1]]('data');          expect(callback).toHaveBeenCalled(); -        expect(log).toEqual('remove();200:data;'); +        expect(log).toEqual('200:data;'); +        expect(scripts).toEqual(removedScripts);          expect(fakeWindow[url[1]]).toBeUndefined();        });      });  | 
