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

178
Vistas
Assert doesn't catch errors

I have this function:

await sendTx(newProxyAddr, false, 'initialize', [0, nullAddr]);

...that produces this error:

Error: VM Exception while processing transaction: reverted with reason string 'Initializable: contract is already initialized'

But when I try to catch the error on a test using:

assert.throws(async () => {
   await sendTx(newProxyAddr, false, 'initialize', [0, nullAddr]);
}, Error, 'Thrown');

..., it tells me:

AssertionError: expected [Function] to throw an error

Am I missing something?

Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You should use Node.js assert.rejects(asyncFn[, error][, message]) API for async function or JS promise.

assert.throws calls getActual(promiseFn) function which will NOT await the promiseFn, see v14.19.3/lib/assert.js#L899

assert.rejects calls await waitForActual(promiseFn) will await the promiseFn, see v14.19.3/lib/assert.js#L909

E.g.

const assert = require('assert');

async function sendTx() {
  throw new Error('error happens');
}

(async () => {
  await assert.rejects(
    async () => {
      await sendTx();
    },
    {
      name: 'Error',
      message: 'error happens',
    },
  );
})();
about 4 years ago · Juan Pablo Isaza Denunciar
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