Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

481
Vistas
La prueba de Jest falla con el código de error ERR_UNHANDLED_REJECTION

¿Por qué sigo recibiendo este código de error ERR_UNHANDLED_REJECTION ?

Caso de prueba:

 beforeEach(() => { jest.resetModules() }) test('A class should be already initialized at first call', async () => { jest.doMock('@google-cloud/firestore', () => class { collection () {} }) const Statistics = require('./index') expect(Statistics.initialized).toBe(true) })

Y el módulo de clase:

 const Firestore = require('@google-cloud/firestore') const Database = new Firestore() class Statistics { constructor () { this.initialized = false // Default field values this.fields = { products: { count: 0, published: 0, updatedAt: new Date() } } this.init() } async init () { const fetched = [] await Database.collection('statistics').get().then(snapshot => { // Check if snapshot is completely empty if (snapshot.docs.length === 0) { // Create new document Object.keys(this.fields).forEach(key => { Database.collection('statistics').doc(key).set(this.fields[key]) fetched[key] = this.fields[key] }) } else { snapshot.forEach(doc => { fetched[doc.id] = doc.data() }) } }) // Setting fetched data to the fields (synchronous) // ... this.initialized = true } } module.exports = new Statistics()

El error proviene de la línea donde estoy recuperando los datos de Firestore: await Database.collection('statistics').get()...

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda