1
1
import { mount } from '@vue/test-utils' ;
2
2
import Button from '../index.vue' ;
3
-
3
+ import { nextTick } from 'vue' ;
4
4
test ( 'emit click event' , ( ) => {
5
5
const wrapper = mount ( Button ) ;
6
6
@@ -16,3 +16,40 @@ test('slot test', async () => {
16
16
} ) ;
17
17
expect ( wrapper . html ( ) ) . toContain ( '按钮测试' ) ;
18
18
} ) ;
19
+ test ( 'should emit click event' , ( ) => {
20
+ const wrapper = mount ( Button ) ;
21
+
22
+ wrapper . trigger ( 'click' ) ;
23
+ expect ( wrapper . emitted ( 'click' ) ) . toHaveLength ( 1 ) ;
24
+ } ) ;
25
+
26
+ test ( 'should not allow click when set disabled props' , async ( ) => {
27
+ const wrapper = mount ( Button , {
28
+ props : {
29
+ disabled : true
30
+ }
31
+ } ) ;
32
+ wrapper . trigger ( 'click' ) ;
33
+ await nextTick ( ) ;
34
+ expect ( wrapper . emitted ( 'click' ) ) . toBeFalsy ( ) ;
35
+ } ) ;
36
+ test ( 'should not emit click event when loading' , ( ) => {
37
+ const wrapper = mount ( Button , {
38
+ props : {
39
+ loading : true
40
+ }
41
+ } ) ;
42
+
43
+ wrapper . trigger ( 'click' ) ;
44
+ expect ( wrapper . emitted ( 'click' ) ) . toBeFalsy ( ) ;
45
+ } ) ;
46
+ test ( 'should change icon class prefix when using icon-class-prefix prop' , ( ) => {
47
+ const wrapper = mount ( Button , {
48
+ props : {
49
+ icon : 'star-fill' ,
50
+ iconClassPrefix : 'my-icon'
51
+ }
52
+ } ) ;
53
+
54
+ expect ( wrapper . html ( ) ) . toMatchSnapshot ( ) ;
55
+ } ) ;
0 commit comments