Skip to content

Commit

Permalink
test: fix test for components with svg files
Browse files Browse the repository at this point in the history
Co-authored-by: Justice Otuya <[email protected]>
  • Loading branch information
justiceotuya and Justice Otuya authored Jul 23, 2023
1 parent adcaa5e commit c9a063f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const customJestConfig = {
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
'^~/(.*)$': '<rootDir>/public/$1',
'^.+\\.(svg)$': '<rootDir>/src/__mocks__/svg.tsx',
},
};

Expand Down
8 changes: 8 additions & 0 deletions src/__mocks__/svg.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React, { SVGProps } from 'react';

const SvgrMock = React.forwardRef<SVGSVGElement, SVGProps<SVGSVGElement>>(
(props, ref) => <svg ref={ref} {...props} />
);

export const ReactComponent = SvgrMock;
export default SvgrMock;
15 changes: 15 additions & 0 deletions src/__tests__/pages/HomePage.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// !STARTERCONF You should delete this page

import { render, screen } from '@testing-library/react';

import HomePage from '@/app/page';

describe('Homepage', () => {
it('renders the Components', () => {
render(<HomePage />);

const heading = screen.getByText(/A starter for Next.js/i);

expect(heading).toBeInTheDocument();
});
});

1 comment on commit c9a063f

@vercel
Copy link

@vercel vercel bot commented on c9a063f Jul 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.