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

431
Views
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
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!