Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update App.test.tsx #73

Merged
merged 1 commit into from
Dec 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions test/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
describe('App Component', () => {
it('renders the Header component', () => {
render(<App />);
const headerElement = screen.getByText(/API BR - Catalog/i);
const headerElement = screen.getByText(/^API BR - Catalog^/i);
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (testing): Incorrect regex usage in header test.

The ^ characters inside the regex string are treated literally, not as start/end anchors. This test will fail if the header text contains any extra characters or whitespace around "API BR - Catalog". Consider using screen.getByRole('heading', { name: /API BR - Catalog/i }) for more robust header testing or fixing the regex to /^API BR - Catalog$/i.

expect(headerElement).toBeInTheDocument();
});

it('renders the ProjectGrid component with projects', () => {
render(<App />);
const projectTitle = screen.getByText(/Sports Agenda/i);
expect(projectTitle).toBeInTheDocument();
const projectTitleVagasAggregator = screen.getByText(/^Vagas Aggregator$/i/);

Check failure on line 14 in test/App.test.tsx

View workflow job for this annotation

GitHub Actions / SonarCloud

test/App.test.tsx > App Component > renders the ProjectGrid component with projects

TestingLibraryElementError: Found multiple elements with the text: /Sports Agenda/i Here are the matching elements: Ignored nodes: comments, script, style <h3 class="css-1lai2va" > Sports Agenda </h3> Ignored nodes: comments, script, style <p class="css-bjz0zr" > 📆 ⚽ Sports Agenda with leagues, teams, matches, and results of most famous footballs leagues. </p> (If this is intentional, then use the `*AllBy*` variant of the query (like `queryAllByText`, `getAllByText`, or `findAllByText`)). Ignored nodes: comments, script, style <body> <div> <header class="css-1l6ca4o" > <img alt="API BR Logo" class="css-xktnp" src="https://apibr.com/ApiBRLogo.png" /> <h1 class="css-1qlq0vm" > API BR - Catalog </h1> <p class="css-1s3q6o1" > Explore Brazilian data APIs </p> </header> <div class="css-10ugj73" data-testid="project-grid" > <div class="css-7e1xth" data-testid="project-card" > <img alt="Vagas Aggregator" class="css-18f4far" src="project-images/vagas.png" /> <div class="css-i52k0e" > <h3 class="css-1lai2va" > Vagas Aggregator </h3> <div class="css-12f48m3" > <a class="css-7t076m" href="https://apibr.com/ui/vagas" target="_blank" > UI </a> <a class="css-7t076m" href="https://apibr.com/vagas/swagger" target="_blank" > Swagger </a> <a class="css-7t076m" href="https://apibr.com/vagas/api/v2" target="_blank" > API (v 2 ) </a> </div> <p class="css-bjz0zr" > 📝🏢 Aggregates open vacancies for developers based on more than 50 GitHub accounts for opportunities and some other sites. </p> </div> </div> <div class="css-7e1xth" data-testid="project-card" > <img alt="Sports Agenda" class="css-18f4far" src="project-images/sports-agenda.png" /> <div class="css-i52k0e" > <h3 class="css-1lai2va" > Sports Agenda </h3> <div class="css-12f48m3" > <a class="css-7t076m" href="https://apibr.com/ui/sports-agenda" target="_blank" > UI </a> <a class="css-7t076m" href="https://apibr.com/sports-agenda/swagger" target="_blank" > Swagger </a> <a class="css-7t076m" href="https://apibr.com/sports-agenda/api/v1" target="_blank" > API (v 1 ) </a> </div> <p class="css-bjz0zr" > 📆 ⚽ Sports Agenda with leagues, teams, matches, and results of most famous footballs leagues. </p> </div> </div> </div> <footer class="css-czkmci" > Developed by <a href="https://guibranco.github.io/?utm_campaign=project&utm_media=api-br-catalog&utm_source=apibr.com" rel="noopener noreferrer" target="_blank" > <img alt="Guilherme Branco Stracini" class="image-rounded" loading="lazy" src="https://guibranco.github.io/photo.png" /> </a> <a href="https://guibranco.github.io/?utm_campaign=project&utm_media=api-br-catalog&utm_source=apibr.com" rel="noopener noreferrer" t

Check failure on line 14 in test/App.test.tsx

View workflow job for this annotation

GitHub Actions / Build and Test

Expression expected.
expect(projectTitleVagasAggregator).toBeInTheDocument();
const projectTitleSportsAgenda = screen.getByText(/^Sports Agenda$/i);
expect(projectTitleSportsAgenda).toBeInTheDocument();
});

it('renders the Footer component', () => {
Expand Down
Loading