Skip to content

Instantly share code, notes, and snippets.

@m-allanson
Created November 16, 2017 14:42
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m-allanson/3dd343db56951ba852fd09a7e52d6a89 to your computer and use it in GitHub Desktop.
Save m-allanson/3dd343db56951ba852fd09a7e52d6a89 to your computer and use it in GitHub Desktop.
Using Jest with Gatsby
// in __mocks__/
// Jest file stub
module.exports = "test-file-stub";
module.exports = {
moduleNameMapper: {
"\\.(jpg|jpeg|png|svg|woff|woff2)$": "<rootDir>/__mocks__/fileMock.js",
// Plain CSS - match css files that don't end with '.module.css' https://regex101.com/r/VzwrKH/4
"^(?!.*\\.module\\.css$).*\\.css$": "<rootDir>/__mocks__/styleMock.js",
// CSS Modules - match files that end with 'module.css'
"\\.module\\.css$": "identity-obj-proxy" // CSS modules
},
setupFiles: ["<rootDir>/src/utils/tempRafShim.js"],
testPathIgnorePatterns: ["/node_modules/", "<rootDir>/.cache/"],
globals: {
__PATH_PREFIX__: ""
}
};
// in __mocks__/
// Jest CSS mock
module.exports = {};
// in utils/
// TODO: Remove this `raf` polyfill once jest v21.3.0 is released
global.requestAnimationFrame = callback => {
setTimeout(callback, 0);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment