@@ -26,6 +26,8 @@ describe('v-b-modal directive', () => {
2626
2727 expect ( wrapper . isVueInstance ( ) ) . toBe ( true )
2828 expect ( wrapper . is ( 'button' ) ) . toBe ( true )
29+ expect ( wrapper . find ( 'button' ) . attributes ( 'tabindex' ) ) . not . toBeDefined ( )
30+ expect ( wrapper . find ( 'button' ) . attributes ( 'role' ) ) . not . toBeDefined ( )
2931 expect ( spy ) . not . toHaveBeenCalled ( )
3032
3133 const $button = wrapper . find ( 'button' )
@@ -36,6 +38,48 @@ describe('v-b-modal directive', () => {
3638 wrapper . destroy ( )
3739 } )
3840
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+
3983 it ( 'works on non-buttons' , async ( ) => {
4084 const localVue = new CreateLocalVue ( )
4185 const spy = jest . fn ( )
@@ -55,7 +99,7 @@ describe('v-b-modal directive', () => {
5599 beforeDestroy ( ) {
56100 this . $root . $off ( EVENT_SHOW , spy )
57101 } ,
58- template : '<span tabindex="0" v-b-modal.test>{{ text }}</span>'
102+ template : '<span v-b-modal.test>{{ text }}</span>'
59103 } )
60104 const wrapper = mount ( App , {
61105 localVue : localVue
@@ -65,6 +109,7 @@ describe('v-b-modal directive', () => {
65109 expect ( wrapper . is ( 'span' ) ) . toBe ( true )
66110 expect ( spy ) . not . toHaveBeenCalled ( )
67111 expect ( wrapper . find ( 'span' ) . attributes ( 'role' ) ) . toBe ( 'button' )
112+ expect ( wrapper . find ( 'span' ) . attributes ( 'tabindex' ) ) . toBe ( '0' )
68113 expect ( wrapper . find ( 'span' ) . text ( ) ) . toBe ( 'span' )
69114
70115 const $span = wrapper . find ( 'span' )
@@ -102,7 +147,7 @@ describe('v-b-modal directive', () => {
102147 beforeDestroy ( ) {
103148 this . $root . $off ( EVENT_SHOW , spy )
104149 } ,
105- template : '<span tabindex="0" v-b-modal.test>{{ text }}</span>'
150+ template : '<span v-b-modal.test>{{ text }}</span>'
106151 } )
107152 const wrapper = mount ( App , {
108153 localVue : localVue
@@ -112,6 +157,7 @@ describe('v-b-modal directive', () => {
112157 expect ( wrapper . is ( 'span' ) ) . toBe ( true )
113158 expect ( spy ) . not . toHaveBeenCalled ( )
114159 expect ( wrapper . find ( 'span' ) . attributes ( 'role' ) ) . toBe ( 'button' )
160+ expect ( wrapper . find ( 'span' ) . attributes ( 'tabindex' ) ) . toBe ( '0' )
115161 expect ( wrapper . find ( 'span' ) . text ( ) ) . toBe ( 'span' )
116162
117163 const $span = wrapper . find ( 'span' )
0 commit comments