Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/core.datasetController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
Expand Down
21 changes: 21 additions & 0 deletions test/specs/core.datasetController.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down