From 7146f7063602b82383211533d98e78f7eb2c03db Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Mon, 9 Jan 2012 10:36:51 -0800 Subject: fix($httpBackend): fix for jsonp requests --- test/service/httpBackendSpec.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'test/service') diff --git a/test/service/httpBackendSpec.js b/test/service/httpBackendSpec.js index 1c6d3a51..55d1a48a 100644 --- a/test/service/httpBackendSpec.js +++ b/test/service/httpBackendSpec.js @@ -19,7 +19,7 @@ describe('$httpBackend', function() { beforeEach(inject(function($injector) { - callbacks = {}; + callbacks = {counter: 0}; $browser = $injector.get('$browser'); fakeBody = {removeChild: jasmine.createSpy('body.removeChild')}; $backend = createHttpBackend($browser, MockXhr, fakeTimeout, callbacks, fakeBody); @@ -115,6 +115,9 @@ describe('$httpBackend', function() { describe('JSONP', function() { + var SCRIPT_URL = /([^\?]*)\?cb=angular\.callbacks\.(.*)/; + + it('should add script tag for JSONP request', function() { callback.andCallFake(function(status, response) { expect(status).toBe(200); @@ -125,10 +128,10 @@ describe('$httpBackend', function() { expect($browser.$$scripts.length).toBe(1); var script = $browser.$$scripts.shift(), - url = script.url.split('?cb='); + url = script.url.match(SCRIPT_URL); - expect(url[0]).toBe('http://example.org/path'); - callbacks[url[1]]('some-data'); + expect(url[1]).toBe('http://example.org/path'); + callbacks[url[2]]('some-data'); script.done(); expect(callback).toHaveBeenCalledOnce(); @@ -140,7 +143,7 @@ describe('$httpBackend', function() { expect($browser.$$scripts.length).toBe(1); var script = $browser.$$scripts.shift(), - callbackId = script.url.split('?cb=')[1]; + callbackId = script.url.match(SCRIPT_URL)[2]; callbacks[callbackId]('some-data'); script.done(); -- cgit v1.2.3