mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
test(angular.copy): add tests for scenarios when target is missing
This commit is contained in:
parent
9e57ce0c7a
commit
035e0130f3
1 changed files with 21 additions and 2 deletions
|
|
@ -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('');
|
||||
|
|
|
|||
Loading…
Reference in a new issue