Skip to content

Instantly share code, notes, and snippets.

@nathansmith
Last active July 22, 2020 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathansmith/881e7a5ee10225784114c42118fc0469 to your computer and use it in GitHub Desktop.
Save nathansmith/881e7a5ee10225784114c42118fc0469 to your computer and use it in GitHub Desktop.
Jest config for testing with Gatsby & SVG files.
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',
},
};
/*
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 = {};
const { createTransformer } = require('babel-jest');
const options = {
presets: ['babel-preset-gatsby'],
};
module.exports = createTransformer(options);
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