Skip to content

Commit

Permalink
fix: inflate functions in arrays (#5646)
Browse files Browse the repository at this point in the history
* fix: inflate functions in arrays

* refactor: handle arrays in separate blocks for clarification
  • Loading branch information
ugur-vaadin authored and vaadin-bot committed Mar 10, 2023
1 parent 3a5b00c commit a89b9f6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/charts/src/helpers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
export function inflateFunctions(config) {
if (Array.isArray(config)) {
config.forEach(inflateFunctions);
return;
}
if (
// Check if param is a primitive/null/undefined value
!(config instanceof Object) ||
// Check if param is a plain object (not an array or HC object)
// Check if param is a plain object (not a HC object)
config.constructor !== Object
) {
return;
Expand Down
10 changes: 10 additions & 0 deletions packages/charts/test/private-api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ describe('vaadin-chart private API', () => {
expect(config.tooltip).to.not.have.property('_fn_formatter');
});

it('should inflate function strings in array', () => {
const exportFunction = 'function () {this.exportChart();}';
// eslint-disable-next-line camelcase
const config = { exporting: { buttons: { contextButton: { menuItems: [{ _fn_onclick: exportFunction }] } } } };
inflateFunctions(config);
const exportButton = config.exporting.buttons.contextButton.menuItems[0];
expect(exportButton.onclick.toString()).to.be.equal(exportFunction);
expect(exportButton).to.not.have.property('_fn_onclick');
});

it('should not try to inflate if a non-object value is passed', () => {
// Check for no errors being thrown
inflateFunctions(null);
Expand Down

0 comments on commit a89b9f6

Please sign in to comment.