@@ -150,15 +150,22 @@ describe('ReactQRCode', () => {
150150 const { container } = render ( < ReactQRCode value = 'test' background = { gradient } /> )
151151
152152 const backgroundPath = screen . getByTestId ( 'background' )
153- const stops = container . querySelectorAll ( `${ selector } #${ BG_GRADIENT_ID } stop` )
153+ const gradientElement = container . querySelector (
154+ `${ selector } [id^="${ BG_GRADIENT_ID } -"]` ,
155+ )
156+
157+ const stops = gradientElement ?. querySelectorAll ( 'stop' )
154158
155- expect ( backgroundPath ) . toHaveAttribute ( 'fill' , `url(#${ BG_GRADIENT_ID } )` )
159+ expect ( backgroundPath ) . toHaveAttribute ( 'fill' , `url(#${ gradientElement ?. id } )` )
156160 expect ( container . querySelector ( `${ selector } ` ) ) . toBeInTheDocument ( )
157- expect ( stops ) . toHaveLength ( 2 )
158- expect ( stops [ 0 ] ) . toHaveAttribute ( 'stop-color' , gradient . stops [ 0 ] . color )
159- expect ( stops [ 0 ] ) . toHaveAttribute ( 'offset' , gradient . stops [ 0 ] . offset )
160- expect ( stops [ 1 ] ) . toHaveAttribute ( 'stop-color' , gradient . stops [ 1 ] . color )
161- expect ( stops [ 1 ] ) . toHaveAttribute ( 'offset' , gradient . stops [ 1 ] . offset )
161+ expect ( stops ?. length ) . toBe ( 2 )
162+
163+ if ( stops ) {
164+ expect ( stops [ 0 ] ) . toHaveAttribute ( 'stop-color' , gradient . stops [ 0 ] . color )
165+ expect ( stops [ 0 ] ) . toHaveAttribute ( 'offset' , gradient . stops [ 0 ] . offset )
166+ expect ( stops [ 1 ] ) . toHaveAttribute ( 'stop-color' , gradient . stops [ 1 ] . color )
167+ expect ( stops [ 1 ] ) . toHaveAttribute ( 'offset' , gradient . stops [ 1 ] . offset )
168+ }
162169 } )
163170 } )
164171
0 commit comments