Skip to content

Commit

Permalink
Typo fixes, add couple of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Feb 3, 2021
1 parent c8d90d5 commit de26e72
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/core/core.datasetController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
Expand Down
2 changes: 1 addition & 1 deletion test/specs/core.controller.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
44 changes: 43 additions & 1 deletion test/specs/helpers.options.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit de26e72

Please sign in to comment.