From 44094c3c4f96b4677f4ce60ece387ab71631c793 Mon Sep 17 00:00:00 2001 From: Josh Kelley Date: Tue, 12 Oct 2021 23:29:29 -0400 Subject: [PATCH] Add a test covering metaset behavior --- src/core/core.controller.js | 2 +- test/specs/core.controller.tests.js | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/core/core.controller.js b/src/core/core.controller.js index bf23252780f..b9376617eb2 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -916,7 +916,7 @@ class Chart { _remove('resize', listener); - // Stop animating and remove metasets, so when re-attached, the animations start from begining. + // Stop animating and remove metasets, so when re-attached, the animations start from beginning. this._stop(); this._resize(0, 0); diff --git a/test/specs/core.controller.tests.js b/test/specs/core.controller.tests.js index cb4eba08c07..48c1586a8cd 100644 --- a/test/specs/core.controller.tests.js +++ b/test/specs/core.controller.tests.js @@ -1121,7 +1121,7 @@ describe('Chart', function() { }); }); - it('should resize the canvas if attached to the DOM after construction with mutiple parents', function(done) { + it('should resize the canvas if attached to the DOM after construction with multiple parents', function(done) { var canvas = document.createElement('canvas'); var wrapper = document.createElement('div'); var wrapper2 = document.createElement('div'); @@ -1848,7 +1848,7 @@ describe('Chart', function() { expect(metasets[2].order).toEqual(3); expect(metasets[3].order).toEqual(4); }); - it('should be moved when datasets are removed from begining', function() { + it('should be moved when datasets are removed from beginning', function() { this.chart.data.datasets.splice(0, 2); this.chart.update(); const metasets = this.chart._metasets; @@ -1910,6 +1910,26 @@ describe('Chart', function() { }); }); + describe('_destroyDatasetMeta', function() { + beforeEach(function() { + this.chart = acquireChart({ + type: 'line', + data: { + datasets: [ + {label: '1', order: 2}, + {label: '2', order: 1}, + {label: '3', order: 4}, + {label: '4', order: 3}, + ] + } + }); + }); + it('cleans up metasets when the chart is destroyed', function() { + this.chart.destroy(); + expect(this.chart._metasets.length).toHaveSize(0); + }); + }); + describe('data visibility', function() { it('should hide a dataset', function() { var chart = acquireChart({