Skip to content

Commit 9a711f8

Browse files
committed
test(button): 解决button组件单元测试问题
1 parent 139fd3a commit 9a711f8

File tree

3 files changed

+90
-74
lines changed

3 files changed

+90
-74
lines changed

packages/devui-vue/devui/button/__tests__/button.spec.ts

Lines changed: 0 additions & 73 deletions
This file was deleted.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { mount } from '@vue/test-utils';
2+
import { Button } from '..';
3+
4+
describe('d-button', () => {
5+
it('variant', () => {
6+
const wrapper = mount({
7+
setup() {
8+
return () => {
9+
return <Button variant="solid">确定</Button>;
10+
}
11+
}
12+
});
13+
expect(wrapper.find('.devui-btn').classes()).toContain('devui-btn-solid');
14+
});
15+
16+
it('size', () => {
17+
const wrapper = mount({
18+
setup() {
19+
return () => {
20+
return <Button size="sm">确定</Button>;
21+
}
22+
}
23+
});
24+
expect(wrapper.find('.devui-btn-sm').exists()).toBeTruthy();
25+
});
26+
27+
it('type', () => {
28+
const wrapper = mount({
29+
setup() {
30+
return () => {
31+
return <Button type="submit">确定</Button>;
32+
}
33+
}
34+
});
35+
expect(wrapper.find('button').attributes('type')).toBe('submit');
36+
});
37+
38+
it('click', async () => {
39+
const handleClick = jest.fn();
40+
const wrapper = mount({
41+
setup() {
42+
return () => {
43+
return <Button onClick={handleClick}>确定</Button>;
44+
}
45+
}
46+
});
47+
await wrapper.find('.devui-btn').trigger('click');
48+
expect(handleClick).toBeCalled();
49+
});
50+
51+
// 目前还不支持 loading
52+
it('loading', async () => {
53+
const handleClick = jest.fn();
54+
const wrapper = mount({
55+
setup() {
56+
return () => {
57+
return <Button loading={true} onClick={handleClick}>确定</Button>;
58+
}
59+
}
60+
});
61+
await wrapper.trigger('click');
62+
expect(handleClick).not.toBeCalled();
63+
});
64+
65+
it('disabled', async () => {
66+
const handleClick = jest.fn();
67+
const wrapper = mount({
68+
setup() {
69+
return () => {
70+
return <Button disabled onClick={handleClick}>确定</Button>;
71+
}
72+
}
73+
});
74+
await wrapper.trigger('click');
75+
expect(handleClick).not.toBeCalled();
76+
});
77+
78+
it('slot', () => {
79+
const btnText = 'vue3 devui';
80+
const wrapper = mount({
81+
setup() {
82+
return () => {
83+
return <Button>{btnText}</Button>;
84+
}
85+
}
86+
});
87+
expect(wrapper.text()).toEqual(btnText);
88+
});
89+
});

packages/devui-vue/devui/button/src/button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import './button.scss';
99
export default defineComponent({
1010
name: 'DButton',
1111
directives: {
12-
devLoading: loadingDirective,
12+
dLoading: loadingDirective,
1313
},
1414
props: buttonProps,
1515
emits: ['click'],

0 commit comments

Comments
 (0)