Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sanity checks for scale options #9624

Merged
merged 1 commit into from Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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