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

125
Views
How to test function arg to be number with Jest

How can I test if a function arg it's a number? I got a simple function of leap year, so I'd like to test if the user inputs a number (not string nor boolean) in "year" argument.

const isLeapYear = (year) => ((year % 100 === 0) ? (year % 400 === 0) : (year % 4 === 0));

I tried to use mock function but didn't work and I have no idea of a solution. Does anybody can help me please?

  it('Verify if the function argument is a number', () => {
     const myMock = jest.fn(2021);
     myMock.mock.calls[0].toBe(expect.any(Number));
  });
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!