-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
requestAnimationFrame warning with React 16 #4545
Comments
Please see this issue: #1644 |
I think this is qualitatively different because React Fiber out-of-the-box now expects RAF to be available. I'm not using RAF at all in my code under test – the warning comes from React itself. |
@cpojer @aaronabramov should we provide a default polyfill then? |
Ditto - I'm getting the same warnings across my test suites. If the answer it so provide our own polyfill in the test environment, so be it... but I'm not sure how to do that for all my component test cases. Any tips there? |
Yeah, let's add one to our jsdom env. |
Can we re-open this issue to track that? |
@mbifulco I managed to get this working for all test cases by loading a simple shim before each spec, using the shim.js: global.requestAnimationFrame = (callback) => {
setTimeout(callback, 0);
}; jest config json: "setupFiles": ["<rootDir>/path/to/shim.js", "<rootDir>/path/to/setup.js"] The shim must be the first file in the setupFiles array if you have any other setup files to load (e.g. The second import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
Enzyme.configure({ adapter: new Adapter() }); Versions: jest 21.2.0, react 16.0.0 |
Beautiful, thank you @jameslockwood - I'll give that a shot. |
Should we include a proper polyfill, or just |
I think we should go with whatever React team recommends now. |
To quote the blog https://facebook.github.io/react/blog/2017/09/26/react-v16.0.html
|
Ah, I can't use yarn test v1.0.1
$ react-scripts test --env=jsdom --coverage
Out of the box, Create React App only supports overriding these Jest options:
• collectCoverageFrom
• coverageReporters
• coverageThreshold
• snapshotSerializers.
These options in your package.json Jest configuration are not currently supported by Create React App:
• setupFiles
If you wish to override other Jest options, you need to eject from the default setup. You can do so by running npm run eject but remember that this is a one-way operation. You may also file an issue with Create React App to discuss supporting more options out of the box.
error Command failed with exit code 1. |
See jestjs/jest#4545 for more info.
Create React App supports test setup, simply create a file named global.requestAnimationFrame = function(callback) {
setTimeout(callback, 0);
}; |
Just including it in setupTests.js didn't fix it for me, but creating a new file with the polyfill and importing that at the top of setupTests.js does it. Like mentioned by @jameslockwood over here: |
For anyone looking for a complete, temporary workaround, my // TODO: Remove this `raf` polyfill once the below issue is sorted
// https://github.com/facebookincubator/create-react-app/issues/3199#issuecomment-332842582
import raf from './tempPolyfills'
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
Enzyme.configure({ adapter: new Adapter() }); and const raf = global.requestAnimationFrame = (cb) => {
setTimeout(cb, 0)
}
export default raf |
@jameslockwood Works with create-react-app ? 😄 |
* Add simple rAF polyfill in jsdom environment Closes #4545 * Fix flow error * Tweak test * Try to log out stderr on CI * Use snake case naming for test file * Update to newest yarn on ci * Revert "Try to log out stderr on CI" This reverts commit 08d58c5. * Remove extra -- from appveyor to avoid warning on newer yarn * Include time since window initialised in rAF implementation
- community practice found at jestjs/jest#4545 (comment)
…ionFrame error in tests See jestjs/jest#4545
…ionFrame error in tests See jestjs/jest#4545
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Do you want to request a feature or report a bug?
Bug-ish
What is the current behavior?
Warning emitted:
If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can
yarn install
andyarn test
.Run any Jest tests with React 16
What is the expected behavior?
No warning
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
Jest v21.2.0
jest-environment-jsdom-11.0.0 v20.0.9
This would be resolved by jsdom/jsdom#1963 upstream. It's just sort of an annoying warning, and I don't want to define a custom environment just to stub polyfill rAF.
I think this is trackable here given that the React docs recommend Jest: https://facebook.github.io/react/docs/test-utils.html, and that it'd be ideal for Jest tests to not emit warnings when used with the latest React release.
The text was updated successfully, but these errors were encountered: