@@ -71,6 +71,45 @@ test.describe('Tooltip', () => {
7171 await expect ( button ) . toHaveAttribute ( 'aria-describedby' , id ) ;
7272 } ) ;
7373
74+ test ( 'should remove the tooltip id from `aria-describedby` attribute when tooltip is removed' , async ( {
75+ fastPage,
76+ } ) => {
77+ const { element, page } = fastPage ;
78+ const button = page . locator ( 'button' ) ;
79+
80+ await fastPage . setTemplate ( /* html */ `
81+ <div style="position: absolute; inset: 200px">
82+ <button id="target">Target</button>
83+ <${ tagName } anchor="target">This is a tooltip</${ tagName } >
84+ <${ tagName } anchor="target">This is another tooltip</${ tagName } >
85+ </div>
86+ ` ) ;
87+
88+ const id1 = await element . nth ( 0 ) . evaluate ( ( node : Tooltip ) => node . id ) ;
89+ const id2 = await element . nth ( 1 ) . evaluate ( ( node : Tooltip ) => node . id ) ;
90+
91+ await expect ( button ) . toHaveAttribute ( 'aria-describedby' , [ id1 , id2 ] . join ( ' ' ) ) ;
92+
93+ await element . nth ( 0 ) . evaluate ( node => {
94+ node . remove ( ) ;
95+ } ) ;
96+
97+ await expect ( button ) . toHaveAttribute ( 'aria-describedby' , id2 ) ;
98+
99+ await button . evaluate (
100+ ( node , [ tagName , id ] ) => {
101+ const tooltip = document . createElement ( tagName ) ;
102+ tooltip . id = id ;
103+ tooltip . setAttribute ( 'anchor' , 'target' ) ;
104+ tooltip . textContent = 'New tooltip' ;
105+ node . after ( tooltip ) ;
106+ } ,
107+ [ tagName , id1 ] ,
108+ ) ;
109+
110+ await expect ( button ) . toHaveAttribute ( 'aria-describedby' , [ id2 , id1 ] . join ( ' ' ) ) ;
111+ } ) ;
112+
74113 test ( 'should not be visible by default' , async ( { fastPage } ) => {
75114 const { element } = fastPage ;
76115
0 commit comments