From 035e0130f35c4ae1636ffc2822be4762c7b2cc4b Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Mon, 11 Feb 2013 22:10:58 -0800 Subject: [PATCH] test(angular.copy): add tests for scenarios when target is missing --- test/AngularSpec.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/test/AngularSpec.js b/test/AngularSpec.js index e29bb16bb58b..1ead504f9586 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -31,7 +31,7 @@ describe('angular', function() { expect(copy(date) === date).toBeFalsy(); }); - it("should copy array", function() { + it("should deeply copy an array into an existing array", function() { var src = [1, {name:"value"}]; var dst = [{key:"v"}]; expect(copy(src, dst)).toBe(dst); @@ -40,6 +40,15 @@ describe('angular', function() { expect(dst[1]).not.toBe(src[1]); }); + it("should deeply copy an array into a new array", function() { + var src = [1, {name:"value"}]; + var dst = copy(src); + expect(src).toEqual([1, {name:"value"}]); + expect(dst).toEqual(src); + expect(dst).not.toBe(src); + expect(dst[1]).not.toBe(src[1]); + }); + it('should copy empty array', function() { var src = []; var dst = [{key: "v"}]; @@ -47,7 +56,7 @@ describe('angular', function() { expect(dst).toEqual([]); }); - it("should copy object", function() { + it("should deeply copy an object into an existing object", function() { var src = {a:{name:"value"}}; var dst = {b:{key:"v"}}; expect(copy(src, dst)).toBe(dst); @@ -56,6 +65,16 @@ describe('angular', function() { expect(dst.a).not.toBe(src.a); }); + it("should deeply copy an object into an existing object", function() { + var src = {a:{name:"value"}}; + var dst = copy(src, dst); + expect(src).toEqual({a:{name:"value"}}); + expect(dst).toEqual(src); + expect(dst).not.toBe(src); + expect(dst.a).toEqual(src.a); + expect(dst.a).not.toBe(src.a); + }); + it("should copy primitives", function() { expect(copy(null)).toEqual(null); expect(copy('')).toBe('');