Skip to content

Commit ca95e0f

Browse files
authored
Merge pull request #24 from apertureless/feature/tests
✅ Add tests for chart instance destroying
2 parents 52c1c50 + 988d8f1 commit ca95e0f

7 files changed

+145
-0
lines changed

test/unit/specs/Bar.spec.js

+21
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,25 @@ describe('BarChart', () => {
4040

4141
expect(vm.$el.querySelector('#barchartprop')).not.to.be.an('undefined')
4242
})
43+
44+
it('should destroy chart instance', (done) => {
45+
const vm = new Vue({
46+
render: function (createElement) {
47+
return createElement(
48+
BarChart
49+
)
50+
},
51+
components: { BarChart }
52+
}).$mount(el)
53+
54+
expect(vm.$children[0]._chart.chart.ctx).not.to.be.null
55+
56+
vm.$destroy()
57+
58+
vm.$nextTick(() => {
59+
vm.$forceUpdate()
60+
expect(vm.$children[0]._chart.chart.ctx).to.be.null
61+
done()
62+
})
63+
})
4364
})

test/unit/specs/Bubble.spec.js

+21
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,25 @@ describe('BubbleChart', () => {
4040

4141
expect(vm.$el.querySelector('#bubblechartprop')).not.to.be.an('undefined')
4242
})
43+
44+
it('should destroy chart instance', (done) => {
45+
const vm = new Vue({
46+
render: function (createElement) {
47+
return createElement(
48+
BubbleChart
49+
)
50+
},
51+
components: { BubbleChart }
52+
}).$mount(el)
53+
54+
expect(vm.$children[0]._chart.chart.ctx).not.to.be.null
55+
56+
vm.$destroy()
57+
58+
vm.$nextTick(() => {
59+
vm.$forceUpdate()
60+
expect(vm.$children[0]._chart.chart.ctx).to.be.null
61+
done()
62+
})
63+
})
4364
})

test/unit/specs/Doughnut.spec.js

+21
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,25 @@ describe('DoughnutChart', () => {
4040

4141
expect(vm.$el.querySelector('#doughnutchartprop')).not.to.be.an('undefined')
4242
})
43+
44+
it('should destroy chart instance', (done) => {
45+
const vm = new Vue({
46+
render: function (createElement) {
47+
return createElement(
48+
DoughnutChart
49+
)
50+
},
51+
components: { DoughnutChart }
52+
}).$mount(el)
53+
54+
expect(vm.$children[0]._chart.chart.ctx).not.to.be.null
55+
56+
vm.$destroy()
57+
58+
vm.$nextTick(() => {
59+
vm.$forceUpdate()
60+
expect(vm.$children[0]._chart.chart.ctx).to.be.null
61+
done()
62+
})
63+
})
4364
})

test/unit/specs/Line.spec.js

+21
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,25 @@ describe('LineChart', () => {
4040

4141
expect(vm.$el.querySelector('#linechartprop')).not.to.be.an('undefined')
4242
})
43+
44+
it('should destroy chart instance', (done) => {
45+
const vm = new Vue({
46+
render: function (createElement) {
47+
return createElement(
48+
LineChart
49+
)
50+
},
51+
components: { LineChart }
52+
}).$mount(el)
53+
54+
expect(vm.$children[0]._chart.chart.ctx).not.to.be.null
55+
56+
vm.$destroy()
57+
58+
vm.$nextTick(() => {
59+
vm.$forceUpdate()
60+
expect(vm.$children[0]._chart.chart.ctx).to.be.null
61+
done()
62+
})
63+
})
4364
})

test/unit/specs/Pie.spec.js

+20
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,24 @@ describe('PieChart', () => {
4040

4141
expect(vm.$el.querySelector('#piechartprop')).not.to.be.an('undefined')
4242
})
43+
it('should destroy chart instance', (done) => {
44+
const vm = new Vue({
45+
render: function (createElement) {
46+
return createElement(
47+
PieChart
48+
)
49+
},
50+
components: { PieChart }
51+
}).$mount(el)
52+
53+
expect(vm.$children[0]._chart.chart.ctx).not.to.be.null
54+
55+
vm.$destroy()
56+
57+
vm.$nextTick(() => {
58+
vm.$forceUpdate()
59+
expect(vm.$children[0]._chart.chart.ctx).to.be.null
60+
done()
61+
})
62+
})
4363
})

test/unit/specs/PolarArea.spec.js

+21
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,25 @@ describe('PolarChart', () => {
4040

4141
expect(vm.$el.querySelector('#polarchartprop')).not.to.be.an('undefined')
4242
})
43+
44+
it('should destroy chart instance', (done) => {
45+
const vm = new Vue({
46+
render: function (createElement) {
47+
return createElement(
48+
PolarChart
49+
)
50+
},
51+
components: { PolarChart }
52+
}).$mount(el)
53+
54+
expect(vm.$children[0]._chart.chart.ctx).not.to.be.null
55+
56+
vm.$destroy()
57+
58+
vm.$nextTick(() => {
59+
vm.$forceUpdate()
60+
expect(vm.$children[0]._chart.chart.ctx).to.be.null
61+
done()
62+
})
63+
})
4364
})

test/unit/specs/Radar.spec.js

+20
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,24 @@ describe('RadarChart', () => {
4040

4141
expect(vm.$el.querySelector('#rodarchartprop')).not.to.be.an('undefined')
4242
})
43+
it('should destroy chart instance', (done) => {
44+
const vm = new Vue({
45+
render: function (createElement) {
46+
return createElement(
47+
RadarChart
48+
)
49+
},
50+
components: { RadarChart }
51+
}).$mount(el)
52+
53+
expect(vm.$children[0]._chart.chart.ctx).not.to.be.null
54+
55+
vm.$destroy()
56+
57+
vm.$nextTick(() => {
58+
vm.$forceUpdate()
59+
expect(vm.$children[0]._chart.chart.ctx).to.be.null
60+
done()
61+
})
62+
})
4363
})

0 commit comments

Comments
 (0)