@@ -118,9 +118,7 @@ def test_switch_does_not_move_when_loading_spinner_is_shown
118118 before_top = track_top
119119
120120 # Show the spinner the same way setLoadingState() does, without racing the request.
121- page . execute_script (
122- "document.querySelector(\" [data-target='toggle-switch.loadingSpinner']\" ).removeAttribute('hidden')"
123- )
121+ unhide ( find ( "[data-target='toggle-switch.loadingSpinner']" , visible : :hidden ) )
124122 assert_selector ( "[data-target='toggle-switch.loadingSpinner']" )
125123
126124 assert_in_delta before_top , track_top , 0.5
@@ -131,20 +129,24 @@ def test_switch_does_not_move_when_error_icon_is_shown
131129
132130 before_top = track_top
133131
134- # Show the error icon the same way setErrorState() does. It's an <svg>, so it has no
135- # `hidden` IDL property and the attribute has to be removed directly.
136- page . execute_script (
137- "document.querySelector(\" [data-target='toggle-switch.errorIcon']\" ).removeAttribute('hidden')"
138- )
132+ # Show the error icon the same way setErrorState() does.
133+ unhide ( find ( "[data-target='toggle-switch.errorIcon']" , visible : :hidden ) )
139134 assert_selector ( "[data-target='toggle-switch.errorIcon']" )
140135
141136 assert_in_delta before_top , track_top , 0.5
142137 end
143138
144139 private
145140
141+ # The status icons are hidden with the `hidden` attribute. `hidden` is an HTMLElement IDL
142+ # property, so `el.hidden = false` silently does nothing on the error icon's <svg>. The
143+ # component removes the attribute, so do the same here.
144+ def unhide ( element )
145+ execute_script ( "arguments[0].removeAttribute('hidden');" , element )
146+ end
147+
146148 def track_top
147- evaluate_script ( "document.querySelector('.ToggleSwitch-track'). getBoundingClientRect().top" )
149+ evaluate_script ( "arguments[0]. getBoundingClientRect().top;" , find ( ".ToggleSwitch-track" ) )
148150 end
149151
150152 def wait_for_spinner
0 commit comments