Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

177
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda