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

140
Views
¿El bloque posterior todavía se ejecuta si antes o si el bloque falla en la prueba de mocha?

Si una prueba de moka se ve así

 describe("create a user") { before("login to system") {} it("execute assertion") {} after("delete the user") {} }

Si el bloque before o it falló, ¿el bloque after todavía se ejecuta o no?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Sí, cuando la prueba falla, se ejecutará after del gancho.

Este código:

 before("login to system", () => { console.log("BEFORE") throw new Error('error'); }) it('testing...', (done) => { console.log("IT") done(); }); after("delete the user", () => { console.log("AFTER") })

salida esto:

 BEFORE 1) "before all" hook: login to system for "testing..." AFTER 0 passing (14ms) 1 failing 1) States Get "before all" hook: login to system for "testing...": Error: error at Context.<anonymous> (test\index.js:22:11) at processImmediate (node:internal/timers:463:21)

También puede consultar esta discusión de github: # 1612 donde aquí dice:

Consulte el ejemplo a continuación, que muestra que after se invoca correctamente después del error beforeEach

El código

 // example.js before(function() { console.log('before'); }); after(function() { console.log('after'); }); describe('suite', function() { beforeEach(function() { throw new Error('In beforeEach'); }); afterEach(function() { console.log('afterEach'); }); it('test', function() { // example }); });

Y la salida.

 // Test run $ mocha example.js before ․afterEach after 0 passing (7ms) 1 failing 1) suite "before each" hook: Error: In beforeEach at Context.<anonymous> (/Users/dstjules/git/mocha/example.js:11:11) at callFn (/usr/local/lib/node_modules/mocha/lib/runnable.js:251:21) at Hook.Runnable.run (/usr/local/lib/node_modules/mocha/lib/runnable.js:244:7) at next (/usr/local/lib/node_modules/mocha/lib/runner.js:259:10) at Immediate._onImmediate (/usr/local/lib/node_modules/mocha/lib/runner.js:276:5) at processImmediate [as _immediateCallback] (timers.js:358:17)
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!