Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find module '../request' error using mock in Jest

Tags:

reactjs

jestjs

I have a test file that has this line

jest.mock('../request');

but it seems couldn't find my mocks folder and it's request file. My folder structure as below

enter image description here

I followed the example of jest here https://github.com/facebook/jest/tree/master/examples/async

Any clue what's wrong?

like image 911
Alex Yong Avatar asked Feb 27 '17 07:02

Alex Yong


1 Answers

The path in jest.mock needs to be the relative path from your test to the module you want to mock (request.js) and the __mocks__ folder needs to be in the folder where the original request.js file is in. From your screenshot its hard to see if its like this. Also your test dont show the jest.mock('../request'); line.

like image 95
Andreas Köberle Avatar answered Sep 28 '22 03:09

Andreas Köberle