@@ -7,6 +7,7 @@ const MODAL_CLOSE_EVENT = 'bv::modal::hidden'
77// Our test application
88const App = {
99 props : [
10+ 'target' ,
1011 'triggers' ,
1112 'show' ,
1213 'noninteractive' ,
@@ -22,7 +23,7 @@ const App = {
2223 ] ,
2324 render ( h ) {
2425 const tipProps = {
25- target : 'foo' ,
26+ target : this . target || 'foo' ,
2627 triggers : this . triggers ,
2728 show : this . show ,
2829 noninteractive : this . noninteractive || false ,
@@ -47,7 +48,8 @@ const App = {
4748 type : 'button' ,
4849 disabled : this . btnDisabled || null ,
4950 title : this . titleAttr || null
50- }
51+ } ,
52+ ref : 'target'
5153 } ,
5254 'text'
5355 ) ,
@@ -283,6 +285,68 @@ describe('b-tooltip', () => {
283285 wrapper . destroy ( )
284286 } )
285287
288+ it ( 'providing the trigger element by function works' , async ( ) => {
289+ jest . useFakeTimers ( )
290+ const container = createContainer ( )
291+ const wrapper = mount ( App , {
292+ attachTo : container ,
293+ propsData : {
294+ target : ( ) => wrapper . vm . $refs . target ,
295+ triggers : 'click' ,
296+ show : false
297+ } ,
298+ slots : {
299+ default : 'title'
300+ }
301+ } )
302+
303+ expect ( wrapper . vm ) . toBeDefined ( )
304+ await waitNT ( wrapper . vm )
305+ await waitRAF ( )
306+ await waitNT ( wrapper . vm )
307+ await waitRAF ( )
308+ jest . runOnlyPendingTimers ( )
309+
310+ expect ( wrapper . element . tagName ) . toBe ( 'ARTICLE' )
311+ expect ( wrapper . attributes ( 'id' ) ) . toBeDefined ( )
312+ expect ( wrapper . attributes ( 'id' ) ) . toEqual ( 'wrapper' )
313+
314+ // The trigger button
315+ const $button = wrapper . find ( 'button' )
316+ expect ( $button . exists ( ) ) . toBe ( true )
317+ expect ( $button . attributes ( 'id' ) ) . toBeDefined ( )
318+ expect ( $button . attributes ( 'id' ) ) . toEqual ( 'foo' )
319+ expect ( $button . attributes ( 'aria-describedby' ) ) . not . toBeDefined ( )
320+
321+ // <b-tooltip> wrapper
322+ const $tipHolder = wrapper . findComponent ( BTooltip )
323+ expect ( $tipHolder . exists ( ) ) . toBe ( true )
324+
325+ // Activate tooltip by trigger
326+ await $button . trigger ( 'click' )
327+ await waitRAF ( )
328+ await waitRAF ( )
329+ jest . runOnlyPendingTimers ( )
330+ await waitNT ( wrapper . vm )
331+ await waitRAF ( )
332+
333+ expect ( $button . attributes ( 'id' ) ) . toBeDefined ( )
334+ expect ( $button . attributes ( 'id' ) ) . toEqual ( 'foo' )
335+ expect ( $button . attributes ( 'aria-describedby' ) ) . toBeDefined ( )
336+ // ID of the tooltip that will be in the body
337+ const adb = $button . attributes ( 'aria-describedby' )
338+
339+ // Find the tooltip element in the document
340+ const tip = document . getElementById ( adb )
341+ expect ( tip ) . not . toBe ( null )
342+ expect ( tip ) . toBeInstanceOf ( HTMLElement )
343+ expect ( tip . tagName ) . toEqual ( 'DIV' )
344+ expect ( tip . classList . contains ( 'tooltip' ) ) . toBe ( true )
345+ expect ( tip . classList . contains ( 'b-tooltip' ) ) . toBe ( true )
346+
347+ wrapper . destroy ( )
348+ } )
349+
286350 it ( 'activating trigger element (click) opens tooltip' , async ( ) => {
287351 jest . useFakeTimers ( )
288352 const wrapper = mount ( App , {
0 commit comments