A jest transformer similar to webpack's file-loader
npm install jest-file-loaderA jest transform to replicate a similar behaviour to webpack's file-loader
Will result in an export of the imported path relative to the configured jest rootDir
Add the transform to your jest configuration:
package.json
``diff`
"jest": {
+ "transform": {
+ "\\.png$": "jest-file-loader"
+ }
}babel-jest
note: if also using babel, you'll have to manually add an entry for also
Default: falseBy default
jest-file-loader generates modules that use CommonJS syntaxe.g.:
`js
module.exports = "src/logo.png";
`You can enable using ES module syntax by setting the
esModule option to truee.g.:
`js
export default "src/logo.png";
`example configuration in package.json
`diff
"jest": {
+ "transform": {
+ "\\.png$": ["jest-file-loader", {"esModule": true}]
+ }
}
``