@@ -12,6 +12,7 @@ import {
1212} from '@vaadin/testing-helpers' ;
1313import sinon from 'sinon' ;
1414import './not-animated-styles.js' ;
15+ import { html , render } from 'lit' ;
1516import { Tooltip } from '../vaadin-tooltip.js' ;
1617import { mouseenter , mouseleave , waitForIntersectionObserver } from './helpers.js' ;
1718
@@ -170,11 +171,35 @@ describe('vaadin-tooltip', () => {
170171 } ) ;
171172
172173 describe ( 'element found' , ( ) => {
173- it ( 'should use for attribute to link target using ID' , ( ) => {
174+ it ( 'should use for attribute to link target using ID' , async ( ) => {
174175 target . setAttribute ( 'id' , 'foo' ) ;
175176 tooltip . for = 'foo' ;
177+ await nextFrame ( ) ;
176178 expect ( tooltip . target ) . to . eql ( target ) ;
177179 } ) ;
180+
181+ it ( 'should still target correct element after sorting the items differently' , async ( ) => {
182+ const container = fixtureSync ( '<div></div>' ) ;
183+ function renderTooltips ( items ) {
184+ render (
185+ html `
186+ ${ items . map (
187+ ( item ) => html `
188+ < vaadin-tooltip for ="${ item } "> </ vaadin-tooltip >
189+ < div id =${ item } > </ div >
190+ ` ,
191+ ) }
192+ ` ,
193+ container ,
194+ ) ;
195+ }
196+
197+ renderTooltips ( [ 'bar' , 'foo' ] ) ;
198+ renderTooltips ( [ 'foo' ] ) ;
199+
200+ await nextFrame ( ) ;
201+ expect ( container . querySelector ( 'vaadin-tooltip[for="foo"]' ) . target ) . to . equal ( container . querySelector ( '#foo' ) ) ;
202+ } ) ;
178203 } ) ;
179204
180205 describe ( 'element not found' , ( ) => {
@@ -186,14 +211,16 @@ describe('vaadin-tooltip', () => {
186211 console . warn . restore ( ) ;
187212 } ) ;
188213
189- it ( 'should warn when element with given ID is not found' , ( ) => {
214+ it ( 'should warn when element with given ID is not found' , async ( ) => {
190215 tooltip . for = 'bar' ;
216+ await nextFrame ( ) ;
191217 expect ( console . warn . called ) . to . be . true ;
192218 } ) ;
193219
194- it ( 'should keep the target when providing incorrect for' , ( ) => {
220+ it ( 'should keep the target when providing incorrect for' , async ( ) => {
195221 tooltip . target = target ;
196222 tooltip . for = 'bar' ;
223+ await nextFrame ( ) ;
197224 expect ( tooltip . target ) . to . eql ( target ) ;
198225 } ) ;
199226 } ) ;
0 commit comments