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

181
Views
Cómo simular o stub Process.argv

¿Cómo me burlo o abrogué el valor de process.argv para que pueda devolver un argumento específico?

Intenté usar sandbox como este:

 beforeEach(() => { sandbox.stub(process.argv.slice(2)[0], 'C:\\home\\project\\assignment').value('--local') }); test("it replace value of node argument", () => { assert(process.argv.slice(2)[0], '--local') }); afterEach(() =>{ sandbox.restore() })

Pero sigo recibiendo un error que dice tratando de stub property * 'C:\home\project\assignment' * of undefined

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

0

Puede modificar el process.argv por programación. ver Modificar entorno de proceso de nodo o tiempo de ejecución de argumentos

 const assert = require('assert'); describe('71476237', () => { let originalArgv; beforeEach(() => { originalArgv = process.argv; }); afterEach(() => { process.argv = originalArgv; }); it('it replace value of node argument', () => { process.argv = process.argv.concat(['node', 'C:\\home\\project\\assignment', '--local']); assert(process.argv.slice(2)[0], '--local'); }); });

Resultado de la prueba:

 71476237 ✓ it replace value of node argument 1 passing (3ms)
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!