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

368
Views
Enzyme espera que se configure un adaptador

Creé una nueva aplicación React mediante create-react-app y quería escribir una prueba unitaria para un componente llamado "MessageBox" que creé en la aplicación. Esta es la prueba unitaria que escribí:

 import MessageBox from "../MessageBox"; import { shallow } from 'enzyme'; import React from 'react'; test('message box', () => { const app = {setState: jest.fn()}; const wrapper = shallow(<MessageBox app={app}/>); wrapper.find('button').at(0).simulate('click'); expect(app.setState).toHaveBeenLastCalledWith({modalIsOpen: false}); });

También agregué un archivo en la carpeta 'src' llamado 'setupTests.js' con el contenido:

 import * as enzyme from 'enzyme'; import * as Adapter from 'enzyme-adapter-react-16'; enzyme.configure({ adapter: new Adapter() });

Lo ejecuté por:

prueba npm

y me dio el error:

Error interno de Enzyme: Enzyme espera que se configure un adaptador, pero no encontró ninguno. Para configurar un adaptador, debe llamar a Enzyme.configure({ > adapter: new Adapter() })

¿Sabes qué puede solucionar este problema?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Agréguelo a su archivo de caso de prueba.

 import React from 'react'; import Adapter from 'enzyme-adapter-react-16'; import { shallow, configure } from 'enzyme'; configure({adapter: new Adapter()}); test('message box', ()=> { ... })
over 4 years ago · Santiago Trujillo Report

0

Además, si no desea importar su archivo setupTests.js en cada archivo de prueba, puede colocarlo en su carpeta package.json:

 "jest": { "setupTestFrameworkScriptFile": "./test/setupTests.js" }

Actualizar:

 Note: setupTestFrameworkScriptFile is deprecated in favor of setupFilesAfterEnv.

https://jestjs.io/docs/en/configuration

over 4 years ago · Santiago Trujillo Report

0

El archivo 'setupTests' debe importarse al archivo de prueba:

 import MessageBox from "../MessageBox"; import { shallow } from 'enzyme'; import React from 'react'; import "../setupTests" test('message box', ()=> { ... })
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!