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

102
Views
Test if the object was modified correctly within the function scope

Let's supose that I have a javascript function that behaves like that:

    function foo() {
        /* unnecessary code...*/
        const sendObjSomewhere = (param) => {/* anom function implementation */}
        return {
            async bar(obj) {
                try {
                    obj.name = obj.name.replace(/\w/g, '');
                    await sendObjSomewhere(obj);
                } catch () {
                     console.error('you messed up');
                }
            }
        }
    }

I tried to show only the important part -- the objName variable and the function. My goal is to test if the obj.name is formated properly.

I've tried to use some libs but, unfortunately, I'm only allowed to use mocha and node native assertions (even more unfortunately, not allowed to extend mocha with other libs). How can I intercept await sendObjSomewhere(obj); and see how the params are being sent? Any other ways to test it are very welcome.

I'm using mocha 9.1.3 and node 16

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!