Skip to content

Commit 035e013

Browse files
committed
test(angular.copy): add tests for scenarios when target is missing
1 parent 9e57ce0 commit 035e013

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

test/AngularSpec.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('angular', function() {
3131
expect(copy(date) === date).toBeFalsy();
3232
});
3333

34-
it("should copy array", function() {
34+
it("should deeply copy an array into an existing array", function() {
3535
var src = [1, {name:"value"}];
3636
var dst = [{key:"v"}];
3737
expect(copy(src, dst)).toBe(dst);
@@ -40,14 +40,23 @@ describe('angular', function() {
4040
expect(dst[1]).not.toBe(src[1]);
4141
});
4242

43+
it("should deeply copy an array into a new array", function() {
44+
var src = [1, {name:"value"}];
45+
var dst = copy(src);
46+
expect(src).toEqual([1, {name:"value"}]);
47+
expect(dst).toEqual(src);
48+
expect(dst).not.toBe(src);
49+
expect(dst[1]).not.toBe(src[1]);
50+
});
51+
4352
it('should copy empty array', function() {
4453
var src = [];
4554
var dst = [{key: "v"}];
4655
expect(copy(src, dst)).toEqual([]);
4756
expect(dst).toEqual([]);
4857
});
4958

50-
it("should copy object", function() {
59+
it("should deeply copy an object into an existing object", function() {
5160
var src = {a:{name:"value"}};
5261
var dst = {b:{key:"v"}};
5362
expect(copy(src, dst)).toBe(dst);
@@ -56,6 +65,16 @@ describe('angular', function() {
5665
expect(dst.a).not.toBe(src.a);
5766
});
5867

68+
it("should deeply copy an object into an existing object", function() {
69+
var src = {a:{name:"value"}};
70+
var dst = copy(src, dst);
71+
expect(src).toEqual({a:{name:"value"}});
72+
expect(dst).toEqual(src);
73+
expect(dst).not.toBe(src);
74+
expect(dst.a).toEqual(src.a);
75+
expect(dst.a).not.toBe(src.a);
76+
});
77+
5978
it("should copy primitives", function() {
6079
expect(copy(null)).toEqual(null);
6180
expect(copy('')).toBe('');

0 commit comments

Comments
 (0)