Skip to content

Commit 6857f9c

Browse files
committed
address pr feedback
1 parent 69bbc60 commit 6857f9c

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

packages/react/src/Testimonial/Testimonial.test.tsx

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react'
1+
import React, {useEffect} from 'react'
22
import {render} from '@testing-library/react'
33
import '@testing-library/jest-dom'
44
import {axe, toHaveNoViolations} from 'jest-axe'
@@ -65,17 +65,28 @@ describe('Testimonial', () => {
6565
expect(figure).toHaveClass('Testimonial')
6666
})
6767

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)
7671

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')
7990
})
8091

8192
it('supports functional ref for Testimonial component', () => {
@@ -140,7 +151,7 @@ describe('Testimonial', () => {
140151
})
141152

142153
it('applies custom quote mark color', () => {
143-
const {getByText} = render(
154+
const {getByRole, getByText} = render(
144155
<Testimonial quoteMarkColor="blue">
145156
<Testimonial.Quote>Quote text</Testimonial.Quote>
146157
<Testimonial.Name>Name</Testimonial.Name>
@@ -149,18 +160,9 @@ describe('Testimonial', () => {
149160

150161
const quoteMark = getByText(leftDoubleQuote)
151162
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-
162163
const figure = getByRole('figure')
163-
expect(figure).toHaveStyle({'--testimonial-accent-color': 'green'})
164+
165+
expect(figure).toHaveStyle({'--testimonial-accent-color': 'blue'})
164166
})
165167

166168
it('renders quote in blockquote element', () => {

0 commit comments

Comments
 (0)