aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMisko Hevery2010-07-22 11:18:32 -0700
committerMisko Hevery2010-07-22 11:18:32 -0700
commit849a05b5a578f19ddc3d24dc9fbd304e0e07612a (patch)
tree3e32e2ab7b8c1ed3f53e5b568990070b5edab4fa /test
parentb5bbfaeb80c3f89c65d14c72cff6f0e1c8aa497a (diff)
downloadangular.js-849a05b5a578f19ddc3d24dc9fbd304e0e07612a.tar.bz2
added jsonp to resources
Diffstat (limited to 'test')
-rw-r--r--test/BrowserSpecs.js28
-rw-r--r--test/ResourceSpec.js12
-rw-r--r--test/angular-mocks.js1
3 files changed, 39 insertions, 2 deletions
diff --git a/test/BrowserSpecs.js b/test/BrowserSpecs.js
index 3ce158b4..a9f61a6b 100644
--- a/test/BrowserSpecs.js
+++ b/test/BrowserSpecs.js
@@ -1,10 +1,15 @@
describe('browser', function(){
- var browser, location;
+ var browser, location, head;
beforeEach(function(){
location = {href:"http://server", hash:""};
- browser = new Browser(location, {});
+ document = jqLite(window.document);
+ head = {
+ scripts: [],
+ append: function(node){head.scripts.push(node);}
+ };
+ browser = new Browser(location, jqLite(window.document), head);
browser.setTimeout = noop;
});
@@ -45,4 +50,23 @@ describe('browser', function(){
});
});
+ describe('xhr', function(){
+ describe('JSON', function(){
+ it('should add script tag for request', function() {
+ var log = "";
+ browser.xhr('JSON', 'http://example.org/path?cb=JSON_CALLBACK', function(code, data){
+ log += code + ':' + data + ';';
+ });
+ expect(head.scripts.length).toEqual(1);
+ var url = head.scripts[0].src.split('?cb=');
+ expect(url[0]).toEqual('http://example.org/path');
+ expect(typeof window[url[1]]).toEqual('function');
+ window[url[1]]('data');
+ expect(log).toEqual('200:data;');
+ expect(typeof window[url[1]]).toEqual('undefined');
+
+ });
+ });
+ });
+
});
diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js
index 4882e70e..6e32ce18 100644
--- a/test/ResourceSpec.js
+++ b/test/ResourceSpec.js
@@ -28,6 +28,18 @@ describe("resource", function() {
resource.route('URL').query();
});
+ it('should ignore slashes of undefinend parameters', function(){
+ var R = resource.route('/Path/:a/:b/:c');
+ xhr.expectGET('/Path').respond({});
+ xhr.expectGET('/Path/1').respond({});
+ xhr.expectGET('/Path/2/3').respond({});
+ xhr.expectGET('/Path/4/5/6').respond({});
+ R.get({});
+ R.get({a:1});
+ R.get({a:2, b:3});
+ R.get({a:4, b:5, c:6});
+ });
+
it("should build resource with default param", function(){
xhr.expectGET('/Order/123/Line/456.visa?minimum=0.05').respond({id:'abc'});
var LineItem = resource.route('/Order/:orderId/Line/:id:verb', {orderId: '123', id: '@id.key', verb:'.visa', minimum:0.05});
diff --git a/test/angular-mocks.js b/test/angular-mocks.js
index 8838b2cd..bac2e800 100644
--- a/test/angular-mocks.js
+++ b/test/angular-mocks.js
@@ -66,6 +66,7 @@ function MockBrowser() {
self.xhr.expectPOST = angular.bind(self, self.xhr.expect, 'POST');
self.xhr.expectDELETE = angular.bind(self, self.xhr.expect, 'DELETE');
self.xhr.expectPUT = angular.bind(self, self.xhr.expect, 'PUT');
+ self.xhr.expectJSON = angular.bind(self, self.xhr.expect, 'JSON');
self.xhr.flush = function() {
while(requests.length) {
requests.pop()();