From 988d8f13b4fbceb208776f615833b9df042ee1ef Mon Sep 17 00:00:00 2001 From: Jakub Juszczak Date: Tue, 20 Dec 2016 20:03:17 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Add=20tests=20for=20chart=20instanc?= =?UTF-8?q?e=20destroying?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/unit/specs/Bar.spec.js | 21 +++++++++++++++++++++ test/unit/specs/Bubble.spec.js | 21 +++++++++++++++++++++ test/unit/specs/Doughnut.spec.js | 21 +++++++++++++++++++++ test/unit/specs/Line.spec.js | 21 +++++++++++++++++++++ test/unit/specs/Pie.spec.js | 20 ++++++++++++++++++++ test/unit/specs/PolarArea.spec.js | 21 +++++++++++++++++++++ test/unit/specs/Radar.spec.js | 20 ++++++++++++++++++++ 7 files changed, 145 insertions(+) diff --git a/test/unit/specs/Bar.spec.js b/test/unit/specs/Bar.spec.js index 715d91e..ee4439a 100644 --- a/test/unit/specs/Bar.spec.js +++ b/test/unit/specs/Bar.spec.js @@ -40,4 +40,25 @@ describe('BarChart', () => { expect(vm.$el.querySelector('#barchartprop')).not.to.be.an('undefined') }) + + it('should destroy chart instance', (done) => { + const vm = new Vue({ + render: function (createElement) { + return createElement( + BarChart + ) + }, + components: { BarChart } + }).$mount(el) + + expect(vm.$children[0]._chart.chart.ctx).not.to.be.null + + vm.$destroy() + + vm.$nextTick(() => { + vm.$forceUpdate() + expect(vm.$children[0]._chart.chart.ctx).to.be.null + done() + }) + }) }) diff --git a/test/unit/specs/Bubble.spec.js b/test/unit/specs/Bubble.spec.js index 749fc89..690a2a3 100644 --- a/test/unit/specs/Bubble.spec.js +++ b/test/unit/specs/Bubble.spec.js @@ -40,4 +40,25 @@ describe('BubbleChart', () => { expect(vm.$el.querySelector('#bubblechartprop')).not.to.be.an('undefined') }) + + it('should destroy chart instance', (done) => { + const vm = new Vue({ + render: function (createElement) { + return createElement( + BubbleChart + ) + }, + components: { BubbleChart } + }).$mount(el) + + expect(vm.$children[0]._chart.chart.ctx).not.to.be.null + + vm.$destroy() + + vm.$nextTick(() => { + vm.$forceUpdate() + expect(vm.$children[0]._chart.chart.ctx).to.be.null + done() + }) + }) }) diff --git a/test/unit/specs/Doughnut.spec.js b/test/unit/specs/Doughnut.spec.js index 37931a8..3288a37 100644 --- a/test/unit/specs/Doughnut.spec.js +++ b/test/unit/specs/Doughnut.spec.js @@ -40,4 +40,25 @@ describe('DoughnutChart', () => { expect(vm.$el.querySelector('#doughnutchartprop')).not.to.be.an('undefined') }) + + it('should destroy chart instance', (done) => { + const vm = new Vue({ + render: function (createElement) { + return createElement( + DoughnutChart + ) + }, + components: { DoughnutChart } + }).$mount(el) + + expect(vm.$children[0]._chart.chart.ctx).not.to.be.null + + vm.$destroy() + + vm.$nextTick(() => { + vm.$forceUpdate() + expect(vm.$children[0]._chart.chart.ctx).to.be.null + done() + }) + }) }) diff --git a/test/unit/specs/Line.spec.js b/test/unit/specs/Line.spec.js index a4edb28..be81aa7 100644 --- a/test/unit/specs/Line.spec.js +++ b/test/unit/specs/Line.spec.js @@ -40,4 +40,25 @@ describe('LineChart', () => { expect(vm.$el.querySelector('#linechartprop')).not.to.be.an('undefined') }) + + it('should destroy chart instance', (done) => { + const vm = new Vue({ + render: function (createElement) { + return createElement( + LineChart + ) + }, + components: { LineChart } + }).$mount(el) + + expect(vm.$children[0]._chart.chart.ctx).not.to.be.null + + vm.$destroy() + + vm.$nextTick(() => { + vm.$forceUpdate() + expect(vm.$children[0]._chart.chart.ctx).to.be.null + done() + }) + }) }) diff --git a/test/unit/specs/Pie.spec.js b/test/unit/specs/Pie.spec.js index 3707cbc..2d5c17e 100644 --- a/test/unit/specs/Pie.spec.js +++ b/test/unit/specs/Pie.spec.js @@ -40,4 +40,24 @@ describe('PieChart', () => { expect(vm.$el.querySelector('#piechartprop')).not.to.be.an('undefined') }) + it('should destroy chart instance', (done) => { + const vm = new Vue({ + render: function (createElement) { + return createElement( + PieChart + ) + }, + components: { PieChart } + }).$mount(el) + + expect(vm.$children[0]._chart.chart.ctx).not.to.be.null + + vm.$destroy() + + vm.$nextTick(() => { + vm.$forceUpdate() + expect(vm.$children[0]._chart.chart.ctx).to.be.null + done() + }) + }) }) diff --git a/test/unit/specs/PolarArea.spec.js b/test/unit/specs/PolarArea.spec.js index b2e563d..868bcc8 100644 --- a/test/unit/specs/PolarArea.spec.js +++ b/test/unit/specs/PolarArea.spec.js @@ -40,4 +40,25 @@ describe('PolarChart', () => { expect(vm.$el.querySelector('#polarchartprop')).not.to.be.an('undefined') }) + + it('should destroy chart instance', (done) => { + const vm = new Vue({ + render: function (createElement) { + return createElement( + PolarChart + ) + }, + components: { PolarChart } + }).$mount(el) + + expect(vm.$children[0]._chart.chart.ctx).not.to.be.null + + vm.$destroy() + + vm.$nextTick(() => { + vm.$forceUpdate() + expect(vm.$children[0]._chart.chart.ctx).to.be.null + done() + }) + }) }) diff --git a/test/unit/specs/Radar.spec.js b/test/unit/specs/Radar.spec.js index 8e58577..47e81ef 100644 --- a/test/unit/specs/Radar.spec.js +++ b/test/unit/specs/Radar.spec.js @@ -40,4 +40,24 @@ describe('RadarChart', () => { expect(vm.$el.querySelector('#rodarchartprop')).not.to.be.an('undefined') }) + it('should destroy chart instance', (done) => { + const vm = new Vue({ + render: function (createElement) { + return createElement( + RadarChart + ) + }, + components: { RadarChart } + }).$mount(el) + + expect(vm.$children[0]._chart.chart.ctx).not.to.be.null + + vm.$destroy() + + vm.$nextTick(() => { + vm.$forceUpdate() + expect(vm.$children[0]._chart.chart.ctx).to.be.null + done() + }) + }) })