Skip to content

Commit bdb3188

Browse files
committed
feat: add test file for components
1 parent 7268857 commit bdb3188

File tree

2 files changed

+51
-8
lines changed

2 files changed

+51
-8
lines changed

tests/the-button.test.ts

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,47 @@
1-
import TheButton from '@/components/TheButton.vue'
21
import { mount } from '@vue/test-utils'
32
import { describe, expect, it } from 'vitest'
3+
import TheButton from '../src/components/TheButton.vue'
44

5-
const text = 'Button'
6-
7-
describe('test use for TheButton.vue', () => {
8-
it('create', () => {
5+
describe('theButton.vue', () => {
6+
it('renders the slot content', () => {
97
const wrapper = mount(TheButton, {
108
slots: {
11-
default: text,
9+
default: '<span>Button Content</span>',
1210
},
1311
})
12+
expect(wrapper.html()).toContain('<span>Button Content</span>')
13+
})
14+
15+
it('is disabled when the disabled prop is true', () => {
16+
const wrapper = mount(TheButton, {
17+
props: {
18+
disabled: true,
19+
},
20+
})
21+
expect(wrapper.attributes('disabled')).toBeDefined()
22+
})
23+
24+
it('shows loading spinner when loading prop is true', () => {
25+
const wrapper = mount(TheButton, {
26+
props: {
27+
loading: true,
28+
},
29+
})
30+
expect(wrapper.find('svg').exists()).toBe(true)
31+
})
32+
33+
it('does not show loading spinner when loading prop is false', () => {
34+
const wrapper = mount(TheButton, {
35+
props: {
36+
loading: false,
37+
},
38+
})
39+
expect(wrapper.find('svg').exists()).toBe(false)
40+
})
1441

15-
expect(wrapper.exists()).toBe(true)
16-
expect(wrapper.text()).toEqual(text)
42+
it('emits a click event when clicked', async () => {
43+
const wrapper = mount(TheButton)
44+
await wrapper.trigger('click')
45+
expect(wrapper.emitted()).toHaveProperty('click')
1746
})
1847
})

tests/the-card.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { mount } from '@vue/test-utils'
2+
import { describe, expect, it } from 'vitest'
3+
import TheCard from '../src/components/TheCard.vue'
4+
5+
describe('theCard.vue', () => {
6+
it('renders the slot content', () => {
7+
const wrapper = mount(TheCard, {
8+
slots: {
9+
default: '<p>Card Content</p>',
10+
},
11+
})
12+
expect(wrapper.html()).toContain('<p>Card Content</p>')
13+
})
14+
})

0 commit comments

Comments
 (0)