Created
November 16, 2017 14:42
-
-
Save m-allanson/3dd343db56951ba852fd09a7e52d6a89 to your computer and use it in GitHub Desktop.
Using Jest with Gatsby
This file contains hidden or 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
// in __mocks__/ | |
// Jest file stub | |
module.exports = "test-file-stub"; |
This file contains hidden or 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
// in __mocks__/ | |
import React from "react"; | |
const mockComponent = name => props => | |
React.createElement(name, props, props.children); | |
export default mockComponent("MockedLink"); |
This file contains hidden or 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 = { | |
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__: "" | |
} | |
}; |
This file contains hidden or 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
// in __mocks__/ | |
// Jest CSS mock | |
module.exports = {}; |
This file contains hidden or 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
// 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