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

153
Views
¿Cuál es el caso de prueba de Mocha por haber detectado un TypeError de una función asíncrona?

Tengo la siguiente función en something.js , un script de navegador.

 async function somethingFunction(value) { try { //Lots of lovely code manipulating 'value', //an improper assignment here by passing 'undefined' //to value argument of function would cause a TypeError //When trying to access property of value (cannot access .test of undefined) let somethingVar = value.test; return somethingVar; } catch (e) { throw new Error(); } }

Y he escrito como prueba como tal:

 describe(`#somethingFunction()`, async function () { context(`Passing undefined as value parameter should be caught be try catch block`, function () { it(`Should return error (TypeError)`, async function () { expect(async function () { await somethingFunction(undefined); }).to.throw(TypeError); }); }); });

En esta prueba, Mocha da:

 AssertionError: expected [Function] to throw 'TypeError'

Pero pasar undefined a esta función, de hecho, causa un error: ¡un TypeError!

¿Se detectan TypeErrors? ¿Cómo probaría esto Mocha?

Tl; dr - ¿Cómo atrapo TypeErrors y hago que Mocha los pruebe?

about 4 years ago · Juan Pablo Isaza
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!