diff --git a/src/highcharts-ng.js b/src/highcharts-ng.js index 3594262..8267de1 100644 --- a/src/highcharts-ng.js +++ b/src/highcharts-ng.js @@ -111,6 +111,7 @@ if (typeof module !== 'undefined' && typeof exports !== 'undefined' && module.ex destination[i] = deepExtend(destination[i] || {}, source[i]); } } else if (angular.isObject(source)) { + destination = angular.isObject(destination) ? destination : {}; for (var property in source) { destination[property] = deepExtend(destination[property] || {}, source[property]); } diff --git a/test/spec/highcharts-ng-utils.js b/test/spec/highcharts-ng-utils.js index 5305f63..ab31863 100644 --- a/test/spec/highcharts-ng-utils.js +++ b/test/spec/highcharts-ng-utils.js @@ -18,5 +18,19 @@ describe('Module: highchartsNg', function () { expect({c: 5, a: {b : 2}}).toEqual(dest.nested); expect(source.nested).not.toBe(dest.nested); })); + + it('should extend undefined', inject(function (highchartsNG) { + var noop = function(){}; + var source = {bar: 'abc', arr: [1, 'two', {}], nested: {a: {b: 2}}, fn: noop}, + dest; + dest = highchartsNG.deepExtend(dest, source); + expect('abc').toEqual(dest.bar); + expect([1, 'two', {}]).toEqual(dest.arr); + expect(noop).toEqual(dest.fn); + expect(source.arr).not.toBe(dest.arr); + expect(source.arr[2]).not.toBe(dest.arr[2]); + expect({a: {b : 2}}).toEqual(dest.nested); + expect(source.nested).not.toBe(dest.nested); + })); });