Skip to content

Commit bf87659

Browse files
committed
address avatar mocking issues for ProfileCard component
1 parent 82ab88f commit bf87659

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

components/ProfileCard/ProfileCard.test.tsx

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,16 @@ import { render, screen } from '@testing-library/react';
55
import ProfileCard from './ProfileCard';
66
import { Profile } from '@/app/types/profile';
77
import { userEvent } from '@testing-library/user-event';
8+
import { type ComponentProps } from 'react';
89

910
jest.mock('@radix-ui/react-avatar', () => {
1011
const actual = jest.requireActual('@radix-ui/react-avatar');
11-
return {
12+
return ({
1213
...actual,
13-
Image: ({ src, alt, ...props }: { src?: string; alt?: string }) => {
14-
if (!src) {
15-
return (
16-
<img
17-
data-testid="avatar-fallback-image"
18-
src="https://static.vecteezy.com/system/resources/previews/024/183/525/non_2x/avatar-of-a-man-portrait-of-a-young-guy-illustration-of-male-character-in-modern-color-style-vector.jpg"
19-
alt="default avatar"
20-
{...props}
21-
/>
22-
);
23-
}
24-
return <img data-testid="avatar-image" src={src} alt={alt} {...props} />;
25-
},
26-
};
14+
Image: (props: ComponentProps<'img'>) => {
15+
return <img {...props}/>;
16+
}
17+
})
2718
});
2819

2920
const testProfile: Profile = {
@@ -91,11 +82,9 @@ describe('ProfileCard', () => {
9182
showEditButton={false}
9283
/>,
9384
);
94-
const avatarFallbackImage = screen.getByTestId('avatar-fallback-image');
95-
expect(avatarFallbackImage).toHaveAttribute(
96-
'src',
97-
'https://static.vecteezy.com/system/resources/previews/024/183/525/non_2x/avatar-of-a-man-portrait-of-a-young-guy-illustration-of-male-character-in-modern-color-style-vector.jpg',
98-
);
85+
86+
const avatarFallbackImage = screen.getByTestId('avatar-fallback');
87+
expect(avatarFallbackImage).toBeInTheDocument();
9988
});
10089

10190
it('Edit Profile Button navigates to the onboarding path after user click', async () => {

0 commit comments

Comments
 (0)