@@ -98,11 +98,12 @@ describe('Hooks', () => {
98
98
test ( 'should warn if element is not focusable' , async ( ) => {
99
99
render ( < TestComponent /> ) ;
100
100
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') ;
102
102
const targetContent = screen . getByTestId ( 'target-content' ) ;
103
103
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 ,
106
107
} ) ;
107
108
108
109
await userEvent . click ( skipLink ) ;
@@ -119,13 +120,20 @@ describe('Hooks', () => {
119
120
} ) ;
120
121
121
122
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 /> ) ;
123
134
124
135
const skipLink = screen . getByRole ( 'link' , { name : / s k i p t o c o n t e n t / i } ) ;
125
136
126
- const targetElement = document . getElementById ( 'main-content' ) ;
127
- targetElement ?. parentNode ?. removeChild ( targetElement ) ;
128
-
129
137
await userEvent . click ( skipLink ) ;
130
138
131
139
await waitFor ( ( ) => {
0 commit comments