Skip to content

Commit

Permalink
test(angular.copy): add tests for scenarios when target is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorMinar committed Feb 12, 2013
1 parent 9e57ce0 commit 035e013
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions test/AngularSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -40,14 +40,23 @@ 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"}];
expect(copy(src, dst)).toEqual([]);
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);
Expand All @@ -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('');
Expand Down

0 comments on commit 035e013

Please sign in to comment.