@@ -184,26 +184,30 @@ describe('ReactQRCode', () => {
184184 }
185185 const { container } = render ( < ReactQRCode value = 'test' gradient = { gradient } /> )
186186
187- const gradientElement = container . querySelector ( `${ selector } #${ GRADIENT_ID } ` )
188- const stops = container . querySelectorAll ( `${ selector } #${ GRADIENT_ID } stop` )
187+ const gradientElement = container . querySelector (
188+ `${ selector } [id^="${ GRADIENT_ID } -"]` ,
189+ )
190+ const stops = gradientElement ?. querySelectorAll ( 'stop' )
189191
190192 expect ( gradientElement ) . toBeInTheDocument ( )
191193 expect ( screen . getByTestId ( 'data-modules' ) ) . toHaveAttribute (
192194 'fill' ,
193- `url(#${ GRADIENT_ID } )` ,
195+ `url(#${ gradientElement ?. id } )` ,
194196 )
195197 screen . getAllByTestId ( 'finder-patterns-outer' ) . forEach ( ( path ) => {
196- expect ( path ) . toHaveAttribute ( 'fill' , `url(#${ GRADIENT_ID } )` )
198+ expect ( path ) . toHaveAttribute ( 'fill' , `url(#${ gradientElement ?. id } )` )
197199 } )
198200 screen . getAllByTestId ( 'finder-patterns-inner' ) . forEach ( ( path ) => {
199- expect ( path ) . toHaveAttribute ( 'fill' , `url(#${ GRADIENT_ID } )` )
201+ expect ( path ) . toHaveAttribute ( 'fill' , `url(#${ gradientElement ?. id } )` )
200202 } )
201203
202204 expect ( stops ) . toHaveLength ( 2 )
203- expect ( stops [ 0 ] ) . toHaveAttribute ( 'stop-color' , gradient . stops [ 0 ] . color )
204- expect ( stops [ 0 ] ) . toHaveAttribute ( 'offset' , gradient . stops [ 0 ] . offset )
205- expect ( stops [ 1 ] ) . toHaveAttribute ( 'stop-color' , gradient . stops [ 1 ] . color )
206- expect ( stops [ 1 ] ) . toHaveAttribute ( 'offset' , gradient . stops [ 1 ] . offset )
205+ if ( stops ) {
206+ expect ( stops [ 0 ] ) . toHaveAttribute ( 'stop-color' , gradient . stops [ 0 ] . color )
207+ expect ( stops [ 0 ] ) . toHaveAttribute ( 'offset' , gradient . stops [ 0 ] . offset )
208+ expect ( stops [ 1 ] ) . toHaveAttribute ( 'stop-color' , gradient . stops [ 1 ] . color )
209+ expect ( stops [ 1 ] ) . toHaveAttribute ( 'offset' , gradient . stops [ 1 ] . offset )
210+ }
207211 } )
208212 } )
209213
0 commit comments