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

111
Views
Burlándose de las funciones de mi base de datos globalmente con broma

Vea la publicación original aquí para más contexto.
tl; dr, tenía una tabla de base de datos con algunas funciones (createOne, findOne, etc.) que logré simular para hacer algunas pruebas unitarias de mi API.

Ahora tengo varias tablas y muchas más pruebas para escribir, y la solución que tengo ahora genera mucha duplicación de código al simular las funciones de la base de datos en cada archivo de prueba. Por lo tanto, ahora me gustaría tener los simulacros disponibles globalmente en todos mis archivos de prueba. He leído mucho sobre esto en todos los foros diferentes y he revisado los documentos oficiales pero sin éxito.

tengo la siguiente estructura rn:

 __tests__ pages api <api tests> src lib database table1.js table2.js __mocks__ (as per the official docs, this doesn't seem to work) table1.js table2.js pages api <files under test that calls database functions>

y luego ejemplo simulacro:

 // __mocks__/table1.js const table1 = jest.createMockFromModule("../table1"); table1.createOne = jest.fn().mockImplementation(async () => return {id: 1}); export default table1; // __tests__/pages/api/route1 jest.mock("src/lib/database/table1"); import {createOne} from "src/lib/database/table1"; /* rest of testing like the original post */

Pero los simulacros no se ejecutan correctamente y createOne regresa indefinido. ¿Cómo hago que los simulacros funcionen globalmente?

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