Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
Test nested components in react using jest

I am new in react and just started learning learning . I want to write a test using react jest for my nested component

const data= {
    bannerTitle: 'storingData',
    image: 'https//:google.png',
    title: 'Benefits',
    content: 'demodata'
}
// ----------------------------------------------------------------------

export default function Content() {
    return (
        <StaticContent data={data} pageTitle='storingData' data-testid="benifits"></StaticContent>
    );
}

where StaticContent have some other nested component like breadcrums, footer etc

My page.test.js page I am trying to built like this.

import { render, screen } from "@testing-library/react";
import Content from '../pages/Content';
import React from 'react';

    const data= {
        bannerTitle: 'storingData',
        image: 'https//:google.png',
        title: 'Benefits',
        content: 'demodata'
    }
//test block
test("renders content correctly", () => {

    render(<Content/>);

//select the elements you want to interact with
    const staticContents = screen.getByTestId("benifits");

//assert the expected result
    expect(staticContents).toHaveTextContent(data);
}); 

I don't know if I am doing correctly or not .Thanks in advance for the help . Also if anyone can suggest from where I could learn react automated test functionalities it would be great for me .

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!