Instantly share code, notes, and snippets.

Embed
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' 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