|
1 | | -import TheButton from '@/components/TheButton.vue' |
2 | 1 | import { mount } from '@vue/test-utils' |
3 | 2 | import { describe, expect, it } from 'vitest' |
| 3 | +import TheButton from '../src/components/TheButton.vue' |
4 | 4 |
|
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', () => { |
9 | 7 | const wrapper = mount(TheButton, { |
10 | 8 | slots: { |
11 | | - default: text, |
| 9 | + default: '<span>Button Content</span>', |
12 | 10 | }, |
13 | 11 | }) |
| 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 | + }) |
14 | 41 |
|
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') |
17 | 46 | }) |
18 | 47 | }) |
0 commit comments