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

131
Views
Is there way to write a unit test for javascript function that calls an html element an does something with it?

I have a function like this:

function modaldisplayer(){
   $('.mymodal').modal('show');
   return 'success';
}

Also, I have a function foo which contains modaldisplayer(); in it. I'm using mocha, jest and chai as framework. How can I unit test function foo? Mocha is not seeing .modal('show') as a function.

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

0

You should look what a changes $('.mymodal').modal('show'); do in DOM tree. Most likely it takes some elements and toggle some CSS-classes.

Then your testing code can just check this elements and classes like this

expect($('some modal element').hasClass('e.g modal-visible')).toBeTrue();
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!