From e4b08a7a09fa499bd569576fe894b68597283e3f Mon Sep 17 00:00:00 2001 From: Brian Hann Date: Mon, 6 May 2013 12:43:43 -0500 Subject: [PATCH] Fixes #394, Array.forEach() assumed to exist IE8 doesn't support the Array prototype's forEach() method, and I used it in grid.initTemplates(). I've fixed this to use angular.forEach() instead and added a test to catch calls in initTemplates() to Array.prototype.forEach() --- src/classes/grid.js | 2 +- test/unit/directivesSpec.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/classes/grid.js b/src/classes/grid.js index 044e7f4e4c..7bc81eaf2f 100644 --- a/src/classes/grid.js +++ b/src/classes/grid.js @@ -220,7 +220,7 @@ var ngGrid = function ($scope, options, sortService, domUtilityService, $filter, var templates = ['rowTemplate', 'aggregateTemplate', 'headerRowTemplate', 'checkboxCellTemplate', 'checkboxHeaderTemplate', 'menuTemplate', 'footerTemplate']; var promises = []; - templates.forEach(function(template) { + angular.forEach(templates, function(template) { promises.push( self.getTemplate(template) ); }); diff --git a/test/unit/directivesSpec.js b/test/unit/directivesSpec.js index 42d28dc1ef..8ab6b658de 100644 --- a/test/unit/directivesSpec.js +++ b/test/unit/directivesSpec.js @@ -266,6 +266,26 @@ describe('directives', function () { }); }); describe('grid', function () { + describe('initTemplates', function() { + it('should not call Array.forEach() on the template list (IE8 does not support)', inject(function ($rootScope, $compile) { + var elm = angular.element( + '
' + ); + $compile(elm)($rootScope); + + spyOn(angular, 'forEach'); + spyOn(Array.prototype, 'forEach'); + + // Manually call the initTemplates() function again + elm.scope().gridOptions.ngGrid.initTemplates(); + + // dump(Array.prototype.forEach.mostRecentCall); + + expect(angular.forEach).toHaveBeenCalled(); + expect(Array.prototype.forEach).not.toHaveBeenCalled(); + })); + }); + describe('sortActual', function(){ it('should maintain row selection post-sort', function(){ scope.gridOptions.selectItem(0, true);