@@ -98,11 +98,12 @@ describe('Hooks', () => {
9898 test ( 'should warn if element is not focusable' , async ( ) => {
9999 render ( < TestComponent /> ) ;
100100
101- const skipLink = screen . getByRole ( ' link', { name : / s k i p t o c o n t e n t / i } ) ;
101+ const skipLink = screen . getByTestId ( 'skip- link') ;
102102 const targetContent = screen . getByTestId ( 'target-content' ) ;
103103
104- jest . spyOn ( targetContent , 'focus' ) . mockImplementationOnce ( ( ) => {
105- throw new Error ( 'focus is not a function' ) ;
104+ Object . defineProperty ( targetContent , 'focus' , {
105+ value : undefined ,
106+ configurable : true ,
106107 } ) ;
107108
108109 await userEvent . click ( skipLink ) ;
@@ -119,13 +120,20 @@ describe('Hooks', () => {
119120 } ) ;
120121
121122 test ( 'should warn if target element is not found' , async ( ) => {
122- render ( < TestComponent /> ) ;
123+ const ComponentWithoutTarget = ( ) => {
124+ useScrollToContent ( ) ;
125+ return (
126+ < >
127+ < a href = "#main-content" data-testid = "skip-link" > Skip to content</ a >
128+ { /* Нет #main-content */ }
129+ </ >
130+ ) ;
131+ } ;
132+
133+ render ( < ComponentWithoutTarget /> ) ;
123134
124135 const skipLink = screen . getByRole ( 'link' , { name : / s k i p t o c o n t e n t / i } ) ;
125136
126- const targetElement = document . getElementById ( 'main-content' ) ;
127- targetElement ?. parentNode ?. removeChild ( targetElement ) ;
128-
129137 await userEvent . click ( skipLink ) ;
130138
131139 await waitFor ( ( ) => {
0 commit comments