@@ -59,60 +59,37 @@ describe('Dropdown', () => {
5959 expect ( dropdownByElement . _element ) . toEqual ( btnDropdown )
6060 } )
6161
62- it ( 'should work on invalid markup' , ( ) => {
63- return new Promise ( resolve => {
64- // TODO: REMOVE in v6
65- fixtureEl . innerHTML = [
66- '<div class="dropdown">' ,
67- ' <div class="dropdown-menu">' ,
68- ' <a class="dropdown-item" href="#">Link</a>' ,
69- ' </div>' ,
70- '</div>'
71- ] . join ( '' )
72-
73- const dropdownElem = fixtureEl . querySelector ( '.dropdown-menu' )
74- const dropdown = new Dropdown ( dropdownElem )
75-
76- dropdownElem . addEventListener ( 'shown.bs.dropdown' , ( ) => {
77- resolve ( )
78- } )
62+ it ( 'should create offset modifier correctly when offset option is a function' , async ( ) => {
63+ fixtureEl . innerHTML = [
64+ '<div class="dropdown">' ,
65+ ' <button class="btn dropdown-toggle" data-bs-toggle="dropdown">Dropdown</button>' ,
66+ ' <div class="dropdown-menu">' ,
67+ ' <a class="dropdown-item" href="#">Secondary link</a>' ,
68+ ' </div>' ,
69+ '</div>'
70+ ] . join ( '' )
7971
80- expect ( ) . nothing ( )
81- dropdown . show ( )
72+ const getOffset = jasmine . createSpy ( 'getOffset' ) . and . returnValue ( [ 10 , 20 ] )
73+ const btnDropdown = fixtureEl . querySelector ( '[data-bs-toggle="dropdown"]' )
74+ const dropdown = new Dropdown ( btnDropdown , {
75+ offset : getOffset
8276 } )
83- } )
84-
85- it ( 'should create offset modifier correctly when offset option is a function' , ( ) => {
86- return new Promise ( resolve => {
87- fixtureEl . innerHTML = [
88- '<div class="dropdown">' ,
89- ' <button class="btn dropdown-toggle" data-bs-toggle="dropdown">Dropdown</button>' ,
90- ' <div class="dropdown-menu">' ,
91- ' <a class="dropdown-item" href="#">Secondary link</a>' ,
92- ' </div>' ,
93- '</div>'
94- ] . join ( '' )
9577
96- const getOffset = jasmine . createSpy ( 'getOffset' ) . and . returnValue ( [ 10 , 20 ] )
97- const btnDropdown = fixtureEl . querySelector ( '[data-bs-toggle="dropdown"]' )
98- const dropdown = new Dropdown ( btnDropdown , {
99- offset : getOffset
100- } )
78+ const offset = dropdown . _getOffset ( )
79+ expect ( typeof offset ) . toEqual ( 'function' )
10180
102- btnDropdown . addEventListener ( 'shown.bs.dropdown' , ( ) => {
103- // Floating UI calls offset function asynchronously
104- setTimeout ( ( ) => {
105- expect ( getOffset ) . toHaveBeenCalled ( )
106- resolve ( )
107- } , 20 )
108- } )
109-
110- const offset = dropdown . _getOffset ( )
81+ const shownPromise = new Promise ( resolve => {
82+ btnDropdown . addEventListener ( 'shown.bs.dropdown' , resolve )
83+ } )
11184
112- expect ( typeof offset ) . toEqual ( 'function' )
85+ dropdown . show ( )
86+ await shownPromise
11387
114- dropdown . show ( )
88+ // Floating UI calls offset function asynchronously
89+ await new Promise ( resolve => {
90+ setTimeout ( resolve , 20 )
11591 } )
92+ expect ( getOffset ) . toHaveBeenCalled ( )
11693 } )
11794
11895 it ( 'should create offset modifier correctly when offset option is a string into data attribute' , ( ) => {
0 commit comments