Skip to content

Commit 320737e

Browse files
committed
test: add shared component tests
1 parent b2eb7bd commit 320737e

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

Diff for: tests/unit/components/shared/Banner.spec.js

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import Vue from 'vue'
2+
import { mount, createLocalVue } from '@vue/test-utils'
3+
import Vuetify from 'vuetify'
4+
import Banner from '@/components/Banner.vue'
5+
6+
describe('Banner', () => {
7+
let wrapper
8+
const localVue = createLocalVue()
9+
10+
Vue.use(Vuetify)
11+
12+
const vuetify = new Vuetify()
13+
14+
beforeEach(() => {
15+
wrapper = mount(Banner, {
16+
localVue,
17+
vuetify
18+
})
19+
})
20+
21+
afterEach(() => {
22+
wrapper.destroy()
23+
})
24+
25+
it('should load the banner', () => {
26+
const banner = wrapper.find('.v-banner')
27+
const progress = wrapper.find('.v-progress-linear')
28+
29+
expect(banner.exists()).toBe(true)
30+
expect(progress.exists()).toBe(false)
31+
})
32+
33+
it('should test component props', async () => {
34+
const banner = wrapper.find('.v-banner')
35+
const icon = wrapper.find('.v-icon')
36+
37+
wrapper.setProps({
38+
icon: 'cog',
39+
text: 'dummy text',
40+
progress: true
41+
})
42+
43+
await wrapper.vm.$nextTick()
44+
45+
// checking if we capture the progress bar (loading)
46+
const newProgressDom = wrapper.find('.v-progress-linear')
47+
48+
expect(wrapper.props().icon).toBe('cog')
49+
expect(icon.classes()).toContain('mdi-cog')
50+
expect(banner.text()).toBe('dummy text')
51+
expect(newProgressDom.exists()).toBe(true)
52+
})
53+
})

Diff for: tests/unit/components/shared/Button.spec.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import Vue from 'vue'
2+
import { mount, createLocalVue } from '@vue/test-utils'
3+
import Vuetify from 'vuetify'
4+
import Button from '@/components/Button.vue'
5+
6+
describe('Button', () => {
7+
let wrapper
8+
const localVue = createLocalVue()
9+
10+
Vue.use(Vuetify)
11+
12+
const vuetify = new Vuetify()
13+
14+
beforeEach(() => {
15+
wrapper = mount(Button, {
16+
localVue,
17+
vuetify,
18+
slots: {
19+
default: "<h3 class='test'>hello from slot</h3>"
20+
}
21+
})
22+
})
23+
24+
afterEach(() => {
25+
wrapper.destroy()
26+
})
27+
28+
it('should load button', () => {
29+
const button = wrapper.find('.v-btn')
30+
const badge = wrapper.find('.v-badge')
31+
const testSlot = wrapper.find('.test')
32+
33+
console.log(button.attributes())
34+
35+
expect(button.exists()).toBe(true)
36+
expect(badge.exists()).toBe(false)
37+
// should load the custom slot
38+
expect(testSlot.exists()).toBe(true)
39+
expect(testSlot.text()).toBe('hello from slot')
40+
})
41+
})

0 commit comments

Comments
 (0)