@@ -26,6 +26,8 @@ describe('v-b-modal directive', () => {
26
26
27
expect ( wrapper . isVueInstance ( ) ) . toBe ( true )
27
expect ( wrapper . isVueInstance ( ) ) . toBe ( true )
28
expect ( wrapper . is ( 'button' ) ) . toBe ( true )
28
expect ( wrapper . is ( 'button' ) ) . toBe ( true )
29
+ expect ( wrapper . find ( 'button' ) . attributes ( 'tabindex' ) ) . not . toBeDefined ( )
30
+ expect ( wrapper . find ( 'button' ) . attributes ( 'role' ) ) . not . toBeDefined ( )
29
expect ( spy ) . not . toHaveBeenCalled ( )
31
expect ( spy ) . not . toHaveBeenCalled ( )
30
32
31
const $button = wrapper . find ( 'button' )
33
const $button = wrapper . find ( 'button' )
@@ -36,6 +38,48 @@ describe('v-b-modal directive', () => {
36
wrapper . destroy ( )
38
wrapper . destroy ( )
37
} )
39
} )
38
40
41
+ it ( 'works on links' , async ( ) => {
42
+ const localVue = new CreateLocalVue ( )
43
+ const spy = jest . fn ( )
44
+
45
+ const App = localVue . extend ( {
46
+ directives : {
47
+ bModal : VBModal
48
+ } ,
49
+ data ( ) {
50
+ return {
51
+ text : 'link'
52
+ }
53
+ } ,
54
+ mounted ( ) {
55
+ this . $root . $on ( EVENT_SHOW , spy )
56
+ } ,
57
+ beforeDestroy ( ) {
58
+ this . $root . $off ( EVENT_SHOW , spy )
59
+ } ,
60
+ template : '<a href="#" v-b-modal.test>{{ text }}</a>'
61
+ } )
62
+ const wrapper = mount ( App , {
63
+ localVue : localVue
64
+ } )
65
+
66
+ expect ( wrapper . isVueInstance ( ) ) . toBe ( true )
67
+ expect ( wrapper . is ( 'a' ) ) . toBe ( true )
68
+ expect ( spy ) . not . toHaveBeenCalled ( )
69
+ expect ( wrapper . find ( 'a' ) . attributes ( 'role' ) ) . toBe ( 'button' )
70
+ expect ( wrapper . find ( 'a' ) . attributes ( 'tabindex' ) ) . not . toBeDefined ( )
71
+ expect ( wrapper . find ( 'a' ) . text ( ) ) . toBe ( 'link' )
72
+
73
+ const $link = wrapper . find ( 'a' )
74
+ $link . trigger ( 'click' )
75
+ expect ( spy ) . toHaveBeenCalledTimes ( 1 )
76
+ expect ( spy ) . toBeCalledWith ( 'test' , $link . element )
77
+ expect ( wrapper . find ( 'a' ) . attributes ( 'role' ) ) . toBe ( 'button' )
78
+ expect ( wrapper . find ( 'a' ) . attributes ( 'tabindex' ) ) . not . toBeDefined ( )
79
+
80
+ wrapper . destroy ( )
81
+ } )
82
+
39
it ( 'works on non-buttons' , async ( ) => {
83
it ( 'works on non-buttons' , async ( ) => {
40
const localVue = new CreateLocalVue ( )
84
const localVue = new CreateLocalVue ( )
41
const spy = jest . fn ( )
85
const spy = jest . fn ( )
@@ -55,7 +99,7 @@ describe('v-b-modal directive', () => {
55
beforeDestroy ( ) {
99
beforeDestroy ( ) {
56
this . $root . $off ( EVENT_SHOW , spy )
100
this . $root . $off ( EVENT_SHOW , spy )
57
} ,
101
} ,
58
- template : '<span tabindex="0" v-b-modal.test>{{ text }}</span>'
102
+ template : '<span v-b-modal.test>{{ text }}</span>'
59
} )
103
} )
60
const wrapper = mount ( App , {
104
const wrapper = mount ( App , {
61
localVue : localVue
105
localVue : localVue
@@ -65,6 +109,7 @@ describe('v-b-modal directive', () => {
65
expect ( wrapper . is ( 'span' ) ) . toBe ( true )
109
expect ( wrapper . is ( 'span' ) ) . toBe ( true )
66
expect ( spy ) . not . toHaveBeenCalled ( )
110
expect ( spy ) . not . toHaveBeenCalled ( )
67
expect ( wrapper . find ( 'span' ) . attributes ( 'role' ) ) . toBe ( 'button' )
111
expect ( wrapper . find ( 'span' ) . attributes ( 'role' ) ) . toBe ( 'button' )
112
+ expect ( wrapper . find ( 'span' ) . attributes ( 'tabindex' ) ) . toBe ( '0' )
68
expect ( wrapper . find ( 'span' ) . text ( ) ) . toBe ( 'span' )
113
expect ( wrapper . find ( 'span' ) . text ( ) ) . toBe ( 'span' )
69
114
70
const $span = wrapper . find ( 'span' )
115
const $span = wrapper . find ( 'span' )
@@ -102,7 +147,7 @@ describe('v-b-modal directive', () => {
102
beforeDestroy ( ) {
147
beforeDestroy ( ) {
103
this . $root . $off ( EVENT_SHOW , spy )
148
this . $root . $off ( EVENT_SHOW , spy )
104
} ,
149
} ,
105
- template : '<span tabindex="0" v-b-modal.test>{{ text }}</span>'
150
+ template : '<span v-b-modal.test>{{ text }}</span>'
106
} )
151
} )
107
const wrapper = mount ( App , {
152
const wrapper = mount ( App , {
108
localVue : localVue
153
localVue : localVue
@@ -112,6 +157,7 @@ describe('v-b-modal directive', () => {
112
expect ( wrapper . is ( 'span' ) ) . toBe ( true )
157
expect ( wrapper . is ( 'span' ) ) . toBe ( true )
113
expect ( spy ) . not . toHaveBeenCalled ( )
158
expect ( spy ) . not . toHaveBeenCalled ( )
114
expect ( wrapper . find ( 'span' ) . attributes ( 'role' ) ) . toBe ( 'button' )
159
expect ( wrapper . find ( 'span' ) . attributes ( 'role' ) ) . toBe ( 'button' )
160
+ expect ( wrapper . find ( 'span' ) . attributes ( 'tabindex' ) ) . toBe ( '0' )
115
expect ( wrapper . find ( 'span' ) . text ( ) ) . toBe ( 'span' )
161
expect ( wrapper . find ( 'span' ) . text ( ) ) . toBe ( 'span' )
116
162
117
const $span = wrapper . find ( 'span' )
163
const $span = wrapper . find ( 'span' )
0 commit comments