Skip to content

Commit d34662e

Browse files
authored
chore(tests): call wrapper.destroy() after each test to release DOM and memory (#2851)
1 parent 01e1a1c commit d34662e

27 files changed

+922
-82
lines changed

src/components/carousel/carousel-slide.spec.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,53 @@ describe('carousel-slide', () => {
55
it('has root element "div"', async () => {
66
const wrapper = mount(CarouselSlide)
77
expect(wrapper.is('div')).toBe(true)
8+
9+
wrapper.destroy()
810
})
911

1012
it('has class carousel-item', async () => {
1113
const wrapper = mount(CarouselSlide)
1214
expect(wrapper.classes()).toContain('carousel-item')
1315
expect(wrapper.classes().length).toBe(1)
16+
17+
wrapper.destroy()
1418
})
1519

1620
it('has role=listitem', async () => {
1721
const wrapper = mount(CarouselSlide)
1822
expect(wrapper.attributes('role')).toBeDefined()
1923
expect(wrapper.attributes('role')).toBe('listitem')
24+
25+
wrapper.destroy()
2026
})
2127

2228
it('has child div.carousel-caption by default', async () => {
2329
const wrapper = mount(CarouselSlide)
2430
expect(wrapper.find('.carousel-caption').exists()).toBe(true)
2531
expect(wrapper.find('.carousel-caption').is('div')).toBe(true)
32+
33+
wrapper.destroy()
2634
})
2735

2836
it('does not have image by default', async () => {
2937
const wrapper = mount(CarouselSlide)
3038
expect(wrapper.find('img').exists()).toBe(false)
39+
40+
wrapper.destroy()
3141
})
3242

3343
it('does not have caption tag h3 by default', async () => {
3444
const wrapper = mount(CarouselSlide)
3545
expect(wrapper.find('h3').exists()).toBe(false)
46+
47+
wrapper.destroy()
3648
})
3749

3850
it('does not have text tag p by default', async () => {
3951
const wrapper = mount(CarouselSlide)
4052
expect(wrapper.find('p').exists()).toBe(false)
53+
54+
wrapper.destroy()
4155
})
4256

4357
it('renders default slot inside carousel-caption', async () => {
@@ -48,6 +62,8 @@ describe('carousel-slide', () => {
4862
})
4963
expect(wrapper.find('.carousel-caption').exists()).toBe(true)
5064
expect(wrapper.find('.carousel-caption').text()).toContain('foobar')
65+
66+
wrapper.destroy()
5167
})
5268

5369
it('has caption tag h3 when prop caption is set', async () => {
@@ -59,6 +75,8 @@ describe('carousel-slide', () => {
5975
const content = wrapper.find('.carousel-caption')
6076
expect(content.find('h3').exists()).toBe(true)
6177
expect(content.find('h3').text()).toBe('foobar')
78+
79+
wrapper.destroy()
6280
})
6381

6482
it('has text tag p when prop text is set', async () => {
@@ -70,6 +88,8 @@ describe('carousel-slide', () => {
7088
const content = wrapper.find('.carousel-caption')
7189
expect(content.find('p').exists()).toBe(true)
7290
expect(content.find('p').text()).toBe('foobar')
91+
92+
wrapper.destroy()
7393
})
7494

7595
it('has custom content tag when prop contentTag is set', async () => {
@@ -80,6 +100,8 @@ describe('carousel-slide', () => {
80100
})
81101
expect(wrapper.find('.carousel-caption').exists()).toBe(true)
82102
expect(wrapper.find('.carousel-caption').is('span')).toBe(true)
103+
104+
wrapper.destroy()
83105
})
84106

85107
it('has display classes on .carousel-caption when prop contentVisibleUp is set', async () => {
@@ -92,6 +114,8 @@ describe('carousel-slide', () => {
92114
expect(wrapper.find('.carousel-caption').classes()).toContain('d-none')
93115
expect(wrapper.find('.carousel-caption').classes()).toContain('d-lg-block')
94116
expect(wrapper.find('.carousel-caption').classes().length).toBe(3)
117+
118+
wrapper.destroy()
95119
})
96120

97121
it('does not have style background when prop background not set', async () => {
@@ -103,6 +127,8 @@ describe('carousel-slide', () => {
103127
// But just in case that changes in the future
104128
expect(true).toBe(true)
105129
}
130+
131+
wrapper.destroy()
106132
})
107133

108134
it('has style background when prop background is set', async () => {
@@ -114,6 +140,8 @@ describe('carousel-slide', () => {
114140
expect(wrapper.attributes('style')).toBeDefined()
115141
expect(wrapper.attributes('style')).toContain('background:')
116142
expect(wrapper.attributes('style')).toContain('rgb(')
143+
144+
wrapper.destroy()
117145
})
118146

119147
it('has style background inherited from carousel parent', async () => {
@@ -127,6 +155,8 @@ describe('carousel-slide', () => {
127155
expect(wrapper.attributes('style')).toBeDefined()
128156
expect(wrapper.attributes('style')).toContain('background:')
129157
expect(wrapper.attributes('style')).toContain('rgb(')
158+
159+
wrapper.destroy()
130160
})
131161

132162
it('has custom caption tag when prop captionTag is set', async () => {
@@ -139,6 +169,8 @@ describe('carousel-slide', () => {
139169
const content = wrapper.find('.carousel-caption')
140170
expect(content.find('h1').exists()).toBe(true)
141171
expect(content.find('h1').text()).toBe('foobar')
172+
173+
wrapper.destroy()
142174
})
143175

144176
it('has custom text tag when prop textTag is set', async () => {
@@ -151,6 +183,8 @@ describe('carousel-slide', () => {
151183
const content = wrapper.find('.carousel-caption')
152184
expect(content.find('span').exists()).toBe(true)
153185
expect(content.find('span').text()).toBe('foobar')
186+
187+
wrapper.destroy()
154188
})
155189

156190
it('has image when prop img-src is set', async () => {
@@ -162,6 +196,8 @@ describe('carousel-slide', () => {
162196
expect(wrapper.find('img').exists()).toBe(true)
163197
expect(wrapper.find('img').attributes('src')).toBeDefined()
164198
expect(wrapper.find('img').attributes('src')).toBe('https://picsum.photos/1024/480/?image=52')
199+
200+
wrapper.destroy()
165201
})
166202

167203
it('has image when prop img-blank is set', async () => {
@@ -173,6 +209,8 @@ describe('carousel-slide', () => {
173209
expect(wrapper.find('img').exists()).toBe(true)
174210
expect(wrapper.find('img').attributes('src')).toBeDefined()
175211
expect(wrapper.find('img').attributes('src')).toContain('data:')
212+
213+
wrapper.destroy()
176214
})
177215

178216
it('has image with alt attribute when prop img-alt is set', async () => {
@@ -186,6 +224,8 @@ describe('carousel-slide', () => {
186224
expect(wrapper.find('img').attributes('src')).toBeDefined()
187225
expect(wrapper.find('img').attributes('alt')).toBeDefined()
188226
expect(wrapper.find('img').attributes('alt')).toBe('foobar')
227+
228+
wrapper.destroy()
189229
})
190230

191231
it('has image with width and height attrs when props img-width and img-height are set', async () => {
@@ -202,6 +242,8 @@ describe('carousel-slide', () => {
202242
expect(wrapper.find('img').attributes('width')).toBe('1024')
203243
expect(wrapper.find('img').attributes('height')).toBeDefined()
204244
expect(wrapper.find('img').attributes('height')).toBe('480')
245+
246+
wrapper.destroy()
205247
})
206248

207249
it('has image with width and height attrs inherited from carousel parent', async () => {
@@ -223,5 +265,7 @@ describe('carousel-slide', () => {
223265
expect(wrapper.find('img').attributes('width')).toBe('1024')
224266
expect(wrapper.find('img').attributes('height')).toBeDefined()
225267
expect(wrapper.find('img').attributes('height')).toBe('480')
268+
269+
wrapper.destroy()
226270
})
227271
})

src/components/dropdown/dropdown-item-button.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ describe('dropdown-item-button', () => {
66
const wrapper = mount(DropdownItemBtn)
77
expect(wrapper.is('button')).toBe(true)
88
expect(wrapper.attributes('type')).toBe('button')
9+
10+
wrapper.destroy()
911
})
1012

1113
it('has class "dropdown-item"', async () => {
1214
const wrapper = mount(DropdownItemBtn)
1315
expect(wrapper.classes()).toContain('dropdown-item')
1416
expect(wrapper.classes()).not.toContain('active')
17+
18+
wrapper.destroy()
1519
})
1620

1721
it('has class "active" when active=true', async () => {
@@ -20,13 +24,17 @@ describe('dropdown-item-button', () => {
2024
})
2125
expect(wrapper.classes()).toContain('active')
2226
expect(wrapper.classes()).toContain('dropdown-item')
27+
28+
wrapper.destroy()
2329
})
2430

2531
it('has attribute "disabled" when disabled=true', async () => {
2632
const wrapper = mount(DropdownItemBtn, {
2733
propsData: { disabled: true }
2834
})
2935
expect(wrapper.attributes('disabled')).toBeDefined()
36+
37+
wrapper.destroy()
3038
})
3139

3240
it('calls dropdown hide(true) method when clicked', async () => {
@@ -48,6 +56,8 @@ describe('dropdown-item-button', () => {
4856
await wrapper.vm.$nextTick()
4957
expect(called).toBe(true)
5058
expect(refocus).toBe(true)
59+
60+
wrapper.destroy()
5161
})
5262

5363
it('does not call dropdown hide(true) method when clicked and disabled', async () => {
@@ -70,5 +80,7 @@ describe('dropdown-item-button', () => {
7080
await wrapper.vm.$nextTick()
7181
expect(called).toBe(false)
7282
expect(refocus).toBe(null)
83+
84+
wrapper.destroy()
7385
})
7486
})

src/components/dropdown/dropdown-item.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ describe('dropdown-item', () => {
66
const wrapper = mount(DropdownItem)
77
expect(wrapper.is('a')).toBe(true)
88
expect(wrapper.attributes('href')).toBe('#')
9+
10+
wrapper.destroy()
911
})
1012

1113
it('has class "dropdown-item"', async () => {
1214
const wrapper = mount(DropdownItem)
1315
expect(wrapper.classes()).toContain('dropdown-item')
1416
expect(wrapper.attributes('href')).toBe('#')
17+
18+
wrapper.destroy()
1519
})
1620

1721
it('calls dropdown hide(true) method when clicked', async () => {
@@ -33,6 +37,8 @@ describe('dropdown-item', () => {
3337
await wrapper.vm.$nextTick()
3438
expect(called).toBe(true)
3539
expect(refocus).toBe(true)
40+
41+
wrapper.destroy()
3642
})
3743

3844
it('does not call dropdown hide(true) method when clicked and disabled', async () => {
@@ -55,5 +61,7 @@ describe('dropdown-item', () => {
5561
await wrapper.vm.$nextTick()
5662
expect(called).toBe(false)
5763
expect(refocus).toBe(null)
64+
65+
wrapper.destroy()
5866
})
5967
})

0 commit comments

Comments
 (0)