diff --git a/src/core/core.datasetController.js b/src/core/core.datasetController.js index 9b7126a93fd..3657f657f31 100644 --- a/src/core/core.datasetController.js +++ b/src/core/core.datasetController.js @@ -1066,7 +1066,7 @@ export default class DatasetController { this._sync(['_removeElements', start, count]); } const newCount = arguments.length - 2; - if (newCount) { + if (newCount > 0) { this._sync(['_insertElements', start, newCount]); } } diff --git a/test/specs/core.datasetController.tests.js b/test/specs/core.datasetController.tests.js index 18011efcb95..d332ba2af22 100644 --- a/test/specs/core.datasetController.tests.js +++ b/test/specs/core.datasetController.tests.js @@ -40,6 +40,27 @@ describe('Chart.DatasetController', function() { }); }); + it('should handle splice with a single argument', function() { + var data = [0, 1, 2, 3, 4, 5]; + var chart = acquireChart({ + type: 'line', + data: { + datasets: [{ + data: data + }] + } + }); + + // splice(0) with no deleteCount should remove all elements from index 0 + // and not throw a RangeError due to negative newCount + expect(function() { + data.splice(0); + chart.update(); + }).not.toThrow(); + + expect(data.length).toBe(0); + }); + it('should not try to delete non existent stacks', function() { function createAndUpdateChart() { var chart = acquireChart({