This is my assetTransformer used during my jest test runs.
const path = require('path');
module.exports = {
process(src, filename, config, options) {
const relativePath = path.relative(config.rootDir, filename);
return `module.exports = ${JSON.stringify({testUri: relativePath})};`;
},
};
And configured in jest.config.js as
moduleNameMapper: {
"\\.(css|less)$": "identity-obj-proxy",
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/assetsTransformer.js",
},
My jest snapshot should atleast have the image path when used. Using "jest": "26.6.3",
My test output is coming with just a "process" method instead
Object {
- "testUri": "../../../src/assets/images/uncheck2.png",
+ "process": [Function process],
}
309 | const imgTick = getByTestId('imgTick');
310 |
> 311 | expect(imgTick.props.source).toEqual({ testUri: '../../../src/assets/images/uncheck2.png' });
| ^
312 | })
313 | });
314 |