@@ -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
@@ -1337,6 +1343,32 @@ describe('Tooltip', () => {
13371343
13381344 expect ( tooltip . _getTitle ( ) ) . toEqual ( 'test' )
13391345 } )
1346+
1347+ it ( 'should call title function with trigger element' , ( ) => {
1348+ fixtureEl . innerHTML = '<a href="#" rel="tooltip" data-foo="bar"></a>'
1349+
1350+ const tooltipEl = fixtureEl . querySelector ( 'a' )
1351+ const tooltip = new Tooltip ( tooltipEl , {
1352+ title ( el ) {
1353+ return el . dataset . foo
1354+ }
1355+ } )
1356+
1357+ expect ( tooltip . _getTitle ( ) ) . toEqual ( 'bar' )
1358+ } )
1359+
1360+ it ( 'should call title function with correct this value' , ( ) => {
1361+ fixtureEl . innerHTML = '<a href="#" rel="tooltip" data-foo="bar"></a>'
1362+
1363+ const tooltipEl = fixtureEl . querySelector ( 'a' )
1364+ const tooltip = new Tooltip ( tooltipEl , {
1365+ title ( ) {
1366+ return this . dataset . foo
1367+ }
1368+ } )
1369+
1370+ expect ( tooltip . _getTitle ( ) ) . toEqual ( 'bar' )
1371+ } )
13401372 } )
13411373
13421374 describe ( 'getInstance' , ( ) => {
0 commit comments