@@ -177,7 +177,10 @@ describe('Tooltip', () => {
177177
178178 const popperConfig = tooltip . _getPopperConfig ( 'top' )
179179
180- expect ( getPopperConfig ) . toHaveBeenCalled ( )
180+ // Ensure that the function was called with the default config.
181+ expect ( getPopperConfig ) . toHaveBeenCalledWith ( jasmine . objectContaining ( {
182+ placement : jasmine . any ( String )
183+ } ) )
181184 expect ( popperConfig . placement ) . toEqual ( 'left' )
182185 } )
183186
@@ -919,10 +922,12 @@ describe('Tooltip', () => {
919922
920923 it ( 'should show a tooltip with custom class provided as a function in config' , ( ) => {
921924 return new Promise ( resolve => {
922- fixtureEl . innerHTML = '<a href="#" rel="tooltip" title="Another tooltip"></a>'
925+ fixtureEl . innerHTML = '<a href="#" rel="tooltip" title="Another tooltip" data-class-a="custom-class-a" data-class-b="custom-class-b" ></a>'
923926
924- const spy = jasmine . createSpy ( 'customClass' ) . and . returnValue ( 'custom-class' )
925927 const tooltipEl = fixtureEl . querySelector ( 'a' )
928+ const spy = jasmine . createSpy ( 'customClass' ) . and . callFake ( function ( el ) {
929+ return `${ el . dataset . classA } ${ this . dataset . classB } `
930+ } )
926931 const tooltip = new Tooltip ( tooltipEl , {
927932 customClass : spy
928933 } )
@@ -931,7 +936,8 @@ describe('Tooltip', () => {
931936 const tip = document . querySelector ( '.tooltip' )
932937 expect ( tip ) . not . toBeNull ( )
933938 expect ( spy ) . toHaveBeenCalled ( )
934- expect ( tip ) . toHaveClass ( 'custom-class' )
939+ expect ( tip ) . toHaveClass ( 'custom-class-a' )
940+ expect ( tip ) . toHaveClass ( 'custom-class-b' )
935941 resolve ( )
936942 } )
937943
@@ -1339,6 +1345,32 @@ describe('Tooltip', () => {
13391345 } )
13401346 } )
13411347
1348+ it ( 'should call title function with trigger element' , ( ) => {
1349+ fixtureEl . innerHTML = '<a href="#" rel="tooltip" data-foo="bar"></a>'
1350+
1351+ const tooltipEl = fixtureEl . querySelector ( 'a' )
1352+ const tooltip = new Tooltip ( tooltipEl , {
1353+ title ( el ) {
1354+ return el . dataset . foo
1355+ }
1356+ } )
1357+
1358+ expect ( tooltip . _getTitle ( ) ) . toEqual ( 'bar' )
1359+ } )
1360+
1361+ it ( 'should call title function with correct this value' , ( ) => {
1362+ fixtureEl . innerHTML = '<a href="#" rel="tooltip" data-foo="bar"></a>'
1363+
1364+ const tooltipEl = fixtureEl . querySelector ( 'a' )
1365+ const tooltip = new Tooltip ( tooltipEl , {
1366+ title ( ) {
1367+ return this . dataset . foo
1368+ }
1369+ } )
1370+
1371+ expect ( tooltip . _getTitle ( ) ) . toEqual ( 'bar' )
1372+ } )
1373+
13421374 describe ( 'getInstance' , ( ) => {
13431375 it ( 'should return tooltip instance' , ( ) => {
13441376 fixtureEl . innerHTML = '<div></div>'
0 commit comments