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

171
Views
Can I have Jest Mocks in a different file and import it into my test file?

I have a custom Hook in a file and I have to mock it quite often for multiple tests. Can I have the mock in a separate file and then just import it into the test?

Hook file

export default function myHook(key) {
    const { state, app } = StateFromSomePlace();

    const setParameter = useCallback(
        newValue => {
            // do something
        },
        [app, key, state.something]
    );

    if (key) {
       // do something
        const parameter = // something;
        return [parameter, setParameter];
    }
}

i want to mock the above using jest to return something (which i can), but i want to do so in an helper/setup file so i can use it in multiple test by just importing the mock.

Thanks for the help in advance. :)

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

0

https://jestjs.io/docs/manual-mocks

You can as per the documentation Follow the instruction

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!