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

173
Views
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 answers
Answer question

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 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!