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

109
Views
.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 answers
Answer question

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 Report
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!