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

241
Visualizações
How to stub a "child_process" function with Sinon, to timeout?

I have a function that uses the exported method execFile from child_process package. I want to test my function. In order to test it, I need to stub the execFile, so it will return only after 5 seconds.

Something like this:

const statStub = sinon.stub(child_process, 'execFile').callsFake((
  file: string,
  args: ReadonlyArray<string> | undefined | null,
  options: ({ encoding?: string | null } & ExecFileOptions) | undefined | null,
  callback: ((error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void) | undefined | null,
) => {
  sleepSomehow(5);

  return execFile(file, args, options, callback);
})

I am not sure that's the correct way, and furthermore I can't really implement this sleepSomehow function. So how do I stub execFile to just stall 5 seconds?

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