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

218
Views
Burlándose del método de publicación de PubSub

Estoy siguiendo este Mock new Function() con Jest para burlarme de PubSub, desafortunadamente no tuve suerte.

 jest.mock('@google-cloud/pubsub', () => jest.fn()) ... const topic = jest.fn((name) => ({ '@type': 'pubsub#topic', name })) const publish = jest.fn((data) => ({ '@type': 'Buffer', data })) const mockedPubSub = PubSub as jest.Mock<PubSub> mockedPubSub.mockImplementation(() => ({ topic }))

Tengo dos errores.

El primero es uno de la línea.

 PubSub as jest.Mock<PubSub>

La conversión del tipo 'typeof PubSub' al tipo 'Mock<PubSub, any>' puede ser un error porque ningún tipo se superpone lo suficiente con el otro. Si esto fue intencional, primero convierta la expresión a 'desconocido'.

Y el segundo está en la última línea.

 mockedPubSub.mockImplementation(() => ({ publish }))

Argumento de tipo '() => { publicar: jest.Mock<{ '@type': string; datos: cualquiera; }, [datos: cualquiera]>; }' no se puede asignar a un parámetro de tipo '(...args: any) => PubSub'.

¿Cómo puedo burlarme de esto?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Encontré la respuesta

 const mockTopic = jest.fn().mockImplementation(() => ({ get: jest.fn(), publish: jest.fn(), })); const mockPublish = jest.fn(); jest.mock('@google-cloud/pubsub', () => ({ __esModule: true, PubSub: jest.fn().mockImplementation(() => ({ topic: mockTopic, publish: mockPublish, })), }))
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!