Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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'
"^(?!.*\\.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: {
// 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
You can’t perform that action at this time.