it('数组判断及转换', function () { expect(lib.isArray).not.toBeUndefined(); expect(lib.isArray(['simply array'])).toBeTruthy(); expect(lib.isArray(new Array(5))).toBeTruthy(); expect(lib.typeOf([])).toBe('array'); var array = lib.toArray(arguments); expect(lib.isArray(array)).toBe(true); array = lib.toArray(null); expect(lib.isArray(array)).toBe(true); array = lib.toArray([1, 2, 3]); expect(lib.isArray(array)).toBe(true); array = lib.toArray({length: 3, 0: 1, 1: 2, 2: 3}); expect(lib.isArray(array)).toBe(true); array = lib.toArray(document.getElementsByTagName('*')); expect(lib.isArray(array)).toBe(true); array = lib.toArray(1); expect(lib.isArray(array)).toBe(true); array = [1, 2]; expect(lib.clone(array) === array).toBeFalsy(); });
it('不复制复杂对象', function () { var A = function () { this.name = '111'; }; var a = new A(); var b = lib.clone(a); expect(a).toBe(b); });
it('复制数组', function () { var a = [1, 2, 3]; var b = lib.clone(a); expect(b).not.toBe(a); expect(b[0]).toBe(1); expect(b[1]).toBe(2); expect(b[2]).toBe(3); });
it('复制对象', function () { var a = { name: 'aaa' }; var b = lib.clone(a); expect(b).not.toBe(a); expect(b.name).toBe('aaa'); });
it('深层复制', function () { var a = { name: 'aaa', age: 1, students: [{ name: 's1', age: 0 }] }; var b = lib.clone(a); expect(b.students).not.toBe(a.students); expect(b.students[0]).not.toBe(a.students[0]); expect(b.students[0]).toEqual(a.students[0]); });