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

424
Visualizações
How to add 'await' at node using jscodeshift?

I recently have spotted jscodeshift and leveraging it for refactoring.

But I can't find a way to add await before the node that I am seeking.

// AS-IS
   userEvent.click(a);
   await userEvent.click(b);

// TO-BE
   await userEvent.click(a);
   await userEvent.click(b);

This is how I query userEvent.click

const getFunctionCall = (obj:string, prop:string) => {
     return source.find(j.CallExpression, {
         callee: {
           type: 'MemberExpression',
           object: {
             name: obj
           }, 
           property: {
             name:prop
           }
         }
     })
 }

const clicks = getFunctionCall('userEvent', 'click');
  
  clicks.forEach(i=> {
    if (i.parentPath.value.type !== 'AwaitExpression') {

      // code goes here

    }
  })

How can I add await before userEvent and let the rest code stay same in this case?

I checked out the document to find out how to build a statement or expression, but it wasn't understandable for me as I've just started to use this. I would appreciate if you can introduce any good materials for this library.

Thanks in advance!

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