Skip to content

Commit

Permalink
Add sanity checks for scale options (#9624)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Sep 6, 2021
1 parent eab0554 commit 3f23aab
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/core/core.config.js
Expand Up @@ -48,6 +48,12 @@ function mergeScaleConfig(config, options) {
// First figure out first scale id's per axis.
Object.keys(configScales).forEach(id => {
const scaleConf = configScales[id];
if (!isObject(scaleConf)) {
return console.error(`Invalid scale configuration for scale: ${id}`);
}
if (scaleConf._proxy) {
return console.warn(`Ignoring resolver passed as options for scale: ${id}`);
}
const axis = determineAxis(id, scaleConf);
const defaultId = getDefaultScaleIDFromAxis(axis, chartIndexAxis);
const defaultScaleOptions = chartDefaults.scales || {};
Expand Down
43 changes: 43 additions & 0 deletions test/specs/core.controller.tests.js
Expand Up @@ -498,6 +498,49 @@ describe('Chart', function() {
expect(Chart.defaults.scales.linear._jasmineCheck).not.toBeDefined();
expect(Chart.defaults.scales.category._jasmineCheck).not.toBeDefined();
});

it('should ignore proxy passed as scale options', function() {
let failure = false;
const chart = acquireChart({
type: 'line',
data: [],
options: {
scales: {
x: {
grid: {
color: ctx => {
if (!ctx.tick) {
failure = true;
}
}
}
}
}
}
});
chart.options.scales = {
x: chart.options.scales.x,
y: {
type: 'linear',
position: 'right'
}
};
chart.update();
expect(failure).toEqual(false);
});

it('should ignore array passed as scale options', function() {
const chart = acquireChart({
type: 'line',
data: [],
options: {
scales: {
xAxes: [{id: 'xAxes', type: 'category'}]
}
}
});
expect(chart.scales.xAxes).not.toBeDefined();
});
});

describe('Updating options', function() {
Expand Down

0 comments on commit 3f23aab

Please sign in to comment.