diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/AngularSpec.js | 8 | ||||
| -rw-r--r-- | test/JsonTest.js | 10 | ||||
| -rw-r--r-- | test/ResourceSpec.js | 9 | ||||
| -rw-r--r-- | test/angular-mocks.js | 11 | ||||
| -rw-r--r-- | test/servicesSpec.js | 9 | ||||
| -rw-r--r-- | test/testabilityPatch.js | 1 |
6 files changed, 38 insertions, 10 deletions
diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 60079c47..de724f03 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -41,4 +41,12 @@ describe("copy", function(){ assertEquals(src.a, dst.a); assertNotSame(src.a, dst.a); }); + + it("should copy primitives", function(){ + expect(copy(null)).toEqual(null); + expect(copy('')).toEqual(''); + expect(copy(123)).toEqual(123); + expect(copy([{key:null}])).toEqual([{key:null}]); + }); + }); diff --git a/test/JsonTest.js b/test/JsonTest.js index 9b275248..1ed56da8 100644 --- a/test/JsonTest.js +++ b/test/JsonTest.js @@ -63,9 +63,9 @@ JsonTest.prototype.testItShouldEscapeUnicode = function () { JsonTest.prototype.testItShouldUTCDates = function() { var date = angular.String.toDate("2009-10-09T01:02:03Z"); - assertEquals('"2009-10-09T01:02:03Z"', toJson(date)); - assertEquals(date.getTime(), - fromJson('"2009-10-09T01:02:03Z"').getTime()); + assertEquals('"2009-10-09T01:02:03Z"', toJson(date)); + assertEquals(date.getTime(), + fromJson('"2009-10-09T01:02:03Z"').getTime()); }; JsonTest.prototype.testItShouldPreventRecursion = function () { @@ -78,3 +78,7 @@ JsonTest.prototype.testItShouldSerializeSameObjectsMultipleTimes = function () { var obj = {a:'b'}; assertEquals('{"A":{"a":"b"},"B":{"a":"b"}}', angular.toJson({A:obj, B:obj})); }; + +JsonTest.prototype.testItShouldNotSerializeUndefinedValues = function () { + assertEquals('{}', angular.toJson({A:undefined})); +}; diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index f0bb6770..d2d52d47 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -81,6 +81,15 @@ describe("resource", function() { expect(callback).wasCalledWith(ccs); }); + it("should have all arguments optional", function(){ + xhr.expectGET('/CreditCard').respond([{id:1}]); + var log = ''; + var ccs = CreditCard.query(function(){ log += 'cb;'; }); + xhr.flush(); + nakedExpect(ccs).toEqual([{id:1}]); + expect(log).toEqual('cb;'); + }); + it('should delete resource', function(){ xhr.expectDELETE("/CreditCard/123").respond({}); diff --git a/test/angular-mocks.js b/test/angular-mocks.js index 715b4d75..6ae91596 100644 --- a/test/angular-mocks.js +++ b/test/angular-mocks.js @@ -26,16 +26,17 @@ function MockBrowser() { var self = this, expectations = {}, requests = []; + this.isMock = true; self.url = "http://server"; self.watches = []; self.xhr = function(method, url, data, callback) { - if (isFunction(data)) { + if (angular.isFunction(data)) { callback = data; data = null; } - if (data && isObject(data)) data = angular.toJson(data); - if (data && isString(data)) url += "|" + data; + if (data && angular.isObject(data)) data = angular.toJson(data); + if (data && angular.isString(data)) url += "|" + data; var expect = expectations[method] || {}; var response = expect[url]; if (!response) { @@ -48,8 +49,8 @@ function MockBrowser() { self.xhr.expectations = expectations; self.xhr.requests = requests; self.xhr.expect = function(method, url, data) { - if (data && isObject(data)) data = angular.toJson(data); - if (data && isString(data)) url += "|" + data; + if (data && angular.isObject(data)) data = angular.toJson(data); + if (data && angular.isString(data)) url += "|" + data; var expect = expectations[method] || (expectations[method] = {}); return { respond: function(response) { diff --git a/test/servicesSpec.js b/test/servicesSpec.js index 112fc374..794d1120 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -149,6 +149,7 @@ describe("service", function(){ expect(scope.$route.current).toEqual(null); scope.$route.when('/NONE', {template:'instant update'}); + scope.$eval(); expect(scope.$route.current.template).toEqual('instant update'); }); }); @@ -187,7 +188,7 @@ describe("service", function(){ describe('bulk', function(){ it('should collect requests', function(){ - scope.$xhr.bulk.url = "/"; + scope.$xhr.bulk.urls["/"] = {match:/.*/}; scope.$xhr.bulk('GET', '/req1', null, callback); scope.$xhr.bulk('POST', '/req2', {post:'data'}, callback); @@ -225,7 +226,11 @@ describe("service", function(){ }); it('should keep track of in flight requests and request only once', function(){ - cache.delegate = scope.$xhr.bulk; + scope.$xhr.bulk.urls['/bulk'] = { + match:function(url){ + return url == '/url'; + } + }; xhr.expectPOST('/bulk', { requests:[{method:'GET', url:'/url', data: null}] }).respond([ diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 572e6a36..4d129f60 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -19,6 +19,7 @@ extend(angular, { 'identity':identity, 'isUndefined': isUndefined, 'isDefined': isDefined, + 'isObject': isObject, 'isString': isString, 'isFunction': isFunction, 'isNumber': isNumber, |
