5

The tested file uses a function that is imported from another file

import {myFunc} from './myFile'

How can I mock return value for this function in my tests for this file? I'm using jest.

skyboyer
  • 19,620
  • 7
  • 50
  • 62
Anna
  • 2,273
  • 4
  • 25
  • 40
  • 1
    Possible duplicate of [How can I mock an ES6 module import using Jest?](https://stackoverflow.com/questions/40465047/how-can-i-mock-an-es6-module-import-using-jest) – Agney Apr 30 '19 at 12:48

1 Answers1

6

This is what worked for me, I'm not sure if it's a good practice tho:

 import * as myFile from "./myFile";
 jest.mock("./myFile");
 myFile.myFunc = jest.fn().mockImplementation(() => {
     return "Some Value";
 });
Anna
  • 2,273
  • 4
  • 25
  • 40