Created
October 19, 2018 16:47
-
-
Save forgo/b1b337765d3f6cb4c73d7b099d626532 to your computer and use it in GitHub Desktop.
Mocha test config helper.
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
| // other good ref: | |
| // https://medium.com/@kayodeniyi/setting-up-tests-for-react-using-mocha-expect-and-enzyme-8f53af96fe7e | |
| // example call: | |
| // mocha --reporter spec mochaTestSetup.js "components/*.spec.js" | |
| const jsdom = require('jsdom').jsdom | |
| process.env.NODE_ENV = 'test' | |
| // ------------------------------- | |
| // Disable webpack-specific features for tests since | |
| // Mocha doesn't know what to do with them. | |
| ;[ '.css', '.scss', '.png', '.jpg', '.svg', '.xml' ].forEach(ext => { | |
| require.extensions[ext] = () => null | |
| }) | |
| // shim for tests to avoid this warning: | |
| // "React depends on requestAnimationFrame. Make sure that you load a polyfill in older browsers." | |
| global.requestAnimationFrame = cb => { | |
| setTimeout(cb, 0) | |
| } | |
| // global define for leaflet-draw use of `L` | |
| // even though it should be defined in src context | |
| global.L = require('leaflet') | |
| // | |
| const enzyme = require('enzyme') | |
| const Adapter = require('enzyme-adapter-react-16') | |
| enzyme.configure({adapter: new Adapter()}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment