Last active
July 22, 2020 03:05
-
-
Save nathansmith/881e7a5ee10225784114c42118fc0469 to your computer and use it in GitHub Desktop.
Jest config for testing with Gatsby & SVG files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
collectCoverageFrom: ['./src/**/*.js', '!./src/fixtures/**', '!./src/svg-icons/'], | |
moduleNameMapper: { | |
'\\.(css|scss)$': '<rootDir>/jest.css.js', | |
'\\.svg$': '<rootDir>/jest.svg.js', | |
}, | |
testPathIgnorePatterns: ['/.cache/', '/public/'], | |
transform: { | |
'\\.jsx?$': '<rootDir>/jest.jsx.js', | |
}, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
NOTE: | |
This file is a no-op. | |
This simply allows for a (S)CSS file to | |
be imported directly, and have no effect. | |
``` | |
import './path/to/file.scss'; | |
``` | |
*/ | |
module.exports = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { createTransformer } = require('babel-jest'); | |
const options = { | |
presets: ['babel-preset-gatsby'], | |
}; | |
module.exports = createTransformer(options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const React = require('react'); | |
const { forwardRef } = React; | |
const component = (props = {}, ref = {}) => { | |
return <svg ref={ref} {...props} />; | |
}; | |
const ReactComponent = forwardRef(component); | |
module.exports = { | |
ReactComponent, | |
default: 'file.svg', | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment