Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

210
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda