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

120
Visualizações
.text() returning "<Button />" instead of the button's text

Basically what's in the title. I have the following code in a component I am writing a test for:

<Button>Edit</Button> // <- Material UI Button component

And this line in my test is failing:

expect(wrapper.find(Button).text()).to.equal("Edit");

with this error:

assert.strictEqual(received, expected)

Expected value to strictly be equal to:
  "Edit"
Received:
  "<Button />"

Message:
  expected '<Button />' to equal 'Edit'

Any idea what might be happening?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think what you are trying to do is something like this:

import { render, within } from '@testing-library/react';
import {Button} from '../components'

it('renders a button with "Edit" label', () => {
  const { container } = render(<Button />);
  const { getByText } = within(container);
  expect(getByText('Edit')).toBeInTheDocument();
});
about 4 years ago · Juan Pablo Isaza Relatório
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