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

379
Views
TypeError: firebase_admin_1.default.messaging no es una función

Estoy tratando de escribir pruebas unitarias usando broma y tratando de burlarme de firebase-admin. Aquí está mi código de aplicación:

 import logger from './logger'; import admin from 'firebase-admin'; class NotificationService { constructor() { admin.initializeApp({ credential: admin.credential.cert({ projectId: 'FCM_PROJECT_ID', privateKey: 'FCM_PRIVATE_KEY' clientEmail: 'FCM_CLIENT_EMAIL' }), }); } public async send(message: TokenMessage): Promise<ApiResponse<string>> { try { await admin.messaging().send(message) } catch (e) { logger.error(e); } } }

Estoy tratando de burlarme del código como a continuación:

 jest.mock('firebase-admin');

Pero está fallando con:

 firebase_admin_1.default.messaging is not a function

¿Cuál es la solución?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Problema: no burlarse de las variables y métodos miembros ( messaging , send ) de firebase-admin.

Arreglar:

 jest.mock('firebase-admin', () => ({ messaging: jest.fn().mockImplementation(() => { return { send: jest .fn() .mockReturnValue('message_id'), }; }), }));

Nota: probablemente también necesite simular la credential e initializeApp la aplicación:

 jest.mock('firebase-admin', () => ({ credential: { cert: jest.fn(), }, initializeApp: jest.fn(), messaging: jest.fn().mockImplementation(() => { return { send: jest .fn() .mockReturnValue('message_id'), }; }), }));
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!