1
- import React from 'react'
1
+ import React , { useEffect } from 'react'
2
2
import { render } from '@testing-library/react'
3
3
import '@testing-library/jest-dom'
4
4
import { axe , toHaveNoViolations } from 'jest-axe'
@@ -65,17 +65,28 @@ describe('Testimonial', () => {
65
65
expect ( figure ) . toHaveClass ( 'Testimonial' )
66
66
} )
67
67
68
- it ( 'supports RefObject for Testimonial component' , ( ) => {
69
- const refObject = React . createRef < HTMLElement > ( )
70
- const { getByRole} = render (
71
- < Testimonial ref = { refObject } >
72
- < Testimonial . Quote > Quote text</ Testimonial . Quote >
73
- < Testimonial . Name > Name</ Testimonial . Name >
74
- </ Testimonial > ,
75
- )
68
+ it ( 'supports RefObject for the root Testimonial component' , ( ) => {
69
+ const MockComponent = ( ) => {
70
+ const ref = React . useRef < HTMLDivElement > ( null )
76
71
77
- const figure = getByRole ( 'figure' )
78
- expect ( refObject . current ) . toBe ( figure )
72
+ useEffect ( ( ) => {
73
+ if ( ref . current ) {
74
+ ref . current . classList . add ( 'test-class' )
75
+ }
76
+ } , [ ref ] )
77
+
78
+ return (
79
+ < Testimonial ref = { ref } >
80
+ < Testimonial . Quote > Quote text</ Testimonial . Quote >
81
+ < Testimonial . Name > Name</ Testimonial . Name >
82
+ </ Testimonial >
83
+ )
84
+ }
85
+
86
+ const { container} = render ( < MockComponent /> )
87
+
88
+ const el = container . querySelector ( '.Testimonial' )
89
+ expect ( el ) . toHaveClass ( 'test-class' )
79
90
} )
80
91
81
92
it ( 'supports functional ref for Testimonial component' , ( ) => {
@@ -140,7 +151,7 @@ describe('Testimonial', () => {
140
151
} )
141
152
142
153
it ( 'applies custom quote mark color' , ( ) => {
143
- const { getByText} = render (
154
+ const { getByRole , getByText} = render (
144
155
< Testimonial quoteMarkColor = "blue" >
145
156
< Testimonial . Quote > Quote text</ Testimonial . Quote >
146
157
< Testimonial . Name > Name</ Testimonial . Name >
@@ -149,18 +160,9 @@ describe('Testimonial', () => {
149
160
150
161
const quoteMark = getByText ( leftDoubleQuote )
151
162
expect ( quoteMark ) . toHaveClass ( 'Testimonial__quoteMark--blue' )
152
- } )
153
-
154
- it ( 'applies custom color as CSS variable' , ( ) => {
155
- const { getByRole} = render (
156
- < Testimonial quoteMarkColor = "green" >
157
- < Testimonial . Quote > Quote text</ Testimonial . Quote >
158
- < Testimonial . Name > Name</ Testimonial . Name >
159
- </ Testimonial > ,
160
- )
161
-
162
163
const figure = getByRole ( 'figure' )
163
- expect ( figure ) . toHaveStyle ( { '--testimonial-accent-color' : 'green' } )
164
+
165
+ expect ( figure ) . toHaveStyle ( { '--testimonial-accent-color' : 'blue' } )
164
166
} )
165
167
166
168
it ( 'renders quote in blockquote element' , ( ) => {
0 commit comments