From de26e725f2193c4eec75146203cfa91c8271aaf8 Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Thu, 4 Feb 2021 00:17:05 +0200 Subject: [PATCH] Typo fixes, add couple of tests --- src/core/core.datasetController.js | 2 +- test/specs/core.controller.tests.js | 2 +- test/specs/helpers.options.tests.js | 44 ++++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/core/core.datasetController.js b/src/core/core.datasetController.js index 48fc9db1db0..4f5cbaa9676 100644 --- a/src/core/core.datasetController.js +++ b/src/core/core.datasetController.js @@ -860,7 +860,7 @@ export default class DatasetController { const options = this.getStyle(index, active); this._resolveAnimations(index, mode, active).update(element, { // When going from active to inactive, we need to update to the shared options. - // This way the onche hovered element will end up with the same original shared options instance, after animation. + // This way the once hovered element will end up with the same original shared options instance, after animation. options: (!active && this.getSharedOptions(options)) || options }); } diff --git a/test/specs/core.controller.tests.js b/test/specs/core.controller.tests.js index 0e91340cbd6..b63fa933788 100644 --- a/test/specs/core.controller.tests.js +++ b/test/specs/core.controller.tests.js @@ -130,7 +130,7 @@ describe('Chart', function() { expect(options.font.size).toBe(defaults.font.size); expect(options.showLine).toBe(defaults.controllers.line.datasets.showLine); expect(options.spanGaps).toBe(true); - // expect(options.hover.onHover).toBe(callback); + expect(options.hover.onHover).toBe(callback); expect(options.hover.mode).toBe('test'); defaults.hover.onHover = null; diff --git a/test/specs/helpers.options.tests.js b/test/specs/helpers.options.tests.js index 7294000fc93..9e0e46f39e1 100644 --- a/test/specs/helpers.options.tests.js +++ b/test/specs/helpers.options.tests.js @@ -246,7 +246,7 @@ describe('Chart.helpers.options', function() { }); }); - describe('_crateResolver', function() { + describe('_createResolver', function() { it('should resolve to raw values', function() { const defaults = { color: 'red', @@ -405,7 +405,49 @@ describe('Chart.helpers.options', function() { }); }); + it('should resolve array of non-indexable objects properly', function() { + const defaults = { + label: { + value: 42, + text: (ctx) => ctx.text + }, + labels: { + _fallback: 'label', + _indexable: false + } + }; + + const options = { + labels: [{text: 'a'}, {text: 'b'}, {value: 1}] + }; + const opts = _attachContext(_createResolver([options, defaults]), {text: 'context'}); + expect(opts.labels).toEqualOptions([ + { + text: 'a', + value: 42 + }, + { + text: 'b', + value: 42 + }, + { + text: 'context', + value: 1 + } + ]); + }); + describe('_indexable and _scriptable', function() { + it('should default to true', function() { + const options = { + array: [1, 2, 3], + func: (ctx) => ctx.index * 10 + }; + const opts = _attachContext(_createResolver([options]), {index: 1}); + expect(opts.array).toEqual(2); + expect(opts.func).toEqual(10); + }); + it('should allow false', function() { const fn = () => 'test'; const options = {