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

472
Views
react-testing-library por qué toBeInTheDocument() no es una función

Aquí está mi código para una información sobre herramientas que alterna la display: block en MouseOver y en la display: none .

 it('should show and hide the message using onMouseOver and onMouseOut events respectively', () => { const { queryByTestId, queryByText } = render( <Tooltip id="test" message="test" />, ) fireEvent.mouseOver(queryByTestId('tooltip')) expect(queryByText('test')).toBeInTheDocument() fireEvent.mouseOut(queryByTestId('tooltip')) expect(queryByText('test')).not.toBeInTheDocument() cleanup() })

Sigo recibiendo el error TypeError: expect(...).toBeInTheDocument no es una función

¿Alguien tiene alguna idea de por qué sucede esto? Mis otras pruebas para renderizar y tomar una instantánea del componente funcionan como se esperaba. Al igual que queryByText y queryByTestId.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

toBeInTheDocument no es parte de RTL. Necesitas instalar jest-dom para habilitarlo.

Y luego impórtelo en sus archivos de prueba mediante: import '@testing-library/jest-dom'

over 4 years ago · Santiago Trujillo Report

0

Como mencionó Giorgio, necesitas instalar jest-dom. Esto es lo que funcionó para mí:

(Estaba usando mecanografiado)

 npm i --save-dev @testing-library/jest-dom

Luego agregue una importación a su setupTests.ts

 import '@testing-library/jest-dom/extend-expect';

Luego, en su jest.config.js puede cargarlo a través de:

 "setupFilesAfterEnv": [ "<rootDir>/src/setupTests.ts" ]
over 4 years ago · Santiago Trujillo Report

0

Cuando haga npm i @testing-library/react , asegúrese de que haya un archivo setupTests.js con la siguiente declaración en él

import '@testing-library/jest-dom/extend-expect';

over 4 years ago · Santiago Trujillo 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!