forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setupMockImages.ts
24 lines (21 loc) · 1.03 KB
/
setupMockImages.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import fs from 'fs';
import path from 'path';
function mockImages(imagePath: string) {
const imageFilenames = fs.readdirSync(path.resolve(__dirname, `../assets/${imagePath}/`));
// eslint-disable-next-line rulesdir/prefer-early-return
imageFilenames.forEach((fileName) => {
if (/\.svg/.test(fileName)) {
jest.mock(`../assets/${imagePath}/${fileName}`, () => () => '');
}
});
}
// We are mocking all images so that Icons and other assets cannot break tests. In the testing environment, importing things like .svg
// directly will lead to undefined variables instead of a component or string (which is what React expects). Loading these assets is
// not required as the test environment does not actually render any UI anywhere and just needs them to noop so the test renderer
// (which is a virtual implemented DOM) can do it's thing.
export default () => {
mockImages('images');
mockImages('images/avatars');
mockImages('images/bankicons');
mockImages('images/product-illustrations');
};