Adds a better error message when the chart type is incorrect. Previously the user got a message about type being undefined.

This gives something that's easier to understand and debug.
This commit is contained in:
etimberg 2017-03-25 19:34:55 -04:00 committed by Evert Timberg
parent 9ea18065ad
commit 06383669be
2 changed files with 32 additions and 1 deletions

View File

@ -293,7 +293,12 @@ module.exports = function(Chart) {
if (meta.controller) {
meta.controller.updateIndex(datasetIndex);
} else {
meta.controller = new Chart.controllers[meta.type](me, datasetIndex);
var ControllerClass = Chart.controllers[meta.type];
if (ControllerClass === undefined) {
throw new Error('"' + meta.type + '" is not a chart type.');
}
meta.controller = new ControllerClass(me, datasetIndex);
newControllers.push(meta.controller);
}
}, me);

View File

@ -144,6 +144,32 @@ describe('Chart', function() {
expect(scaleOptions.xAxes[0].position).toBe('bottom');
expect(scaleOptions.yAxes[0].position).toBe('left');
});
it('should throw an error if the chart type is incorrect', function() {
function createChart() {
acquireChart({
type: 'area',
data: {
datasets: [{
label: 'first',
data: [10, 20]
}],
labels: ['0', '1'],
},
options: {
scales: {
xAxes: [{
position: 'left',
}],
yAxes: [{
position: 'bottom'
}]
}
}
});
}
expect(createChart).toThrow(new Error('"area" is not a chart type.'));
});
});
describe('config.options.responsive: false', function() {