@@ -177,7 +177,10 @@ describe('Tooltip', () => {
177
177
178
178
const popperConfig = tooltip . _getPopperConfig ( 'top' )
179
179
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
+ } ) )
181
184
expect ( popperConfig . placement ) . toEqual ( 'left' )
182
185
} )
183
186
@@ -919,10 +922,12 @@ describe('Tooltip', () => {
919
922
920
923
it ( 'should show a tooltip with custom class provided as a function in config' , ( ) => {
921
924
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>'
923
926
924
- const spy = jasmine . createSpy ( 'customClass' ) . and . returnValue ( 'custom-class' )
925
927
const tooltipEl = fixtureEl . querySelector ( 'a' )
928
+ const spy = jasmine . createSpy ( 'customClass' ) . and . callFake ( function ( el ) {
929
+ return `${ el . dataset . classA } ${ this . dataset . classB } `
930
+ } )
926
931
const tooltip = new Tooltip ( tooltipEl , {
927
932
customClass : spy
928
933
} )
@@ -931,7 +936,8 @@ describe('Tooltip', () => {
931
936
const tip = document . querySelector ( '.tooltip' )
932
937
expect ( tip ) . not . toBeNull ( )
933
938
expect ( spy ) . toHaveBeenCalled ( )
934
- expect ( tip ) . toHaveClass ( 'custom-class' )
939
+ expect ( tip ) . toHaveClass ( 'custom-class-a' )
940
+ expect ( tip ) . toHaveClass ( 'custom-class-b' )
935
941
resolve ( )
936
942
} )
937
943
@@ -1337,6 +1343,32 @@ describe('Tooltip', () => {
1337
1343
1338
1344
expect ( tooltip . _getTitle ( ) ) . toEqual ( 'test' )
1339
1345
} )
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
+ } )
1340
1372
} )
1341
1373
1342
1374
describe ( 'getInstance' , ( ) => {
0 commit comments