Saturday, 9 October 2021

How to mock all files in a folder in jest

I have files as follows

widgets
|
 --tabs
    |
     -- __mocks_
        |
         -- index.ts
     -- index.ts
 --button
    |
     -- __mocks_
        |
         -- index.ts
     -- index.ts

Its imported/used in files as

import { Button } from 'common/widgets/button';

I can individually mock each of these.

jest.mock('common/widgets/tabs');
jest.mock('common/widgets/button');

But is there a way to mock them all like add all these to file and import them or do like below with a common mock folder and an index file.

jest.mock('common/widgets');


from How to mock all files in a folder in jest

No comments:

Post a Comment