-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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 warnings on tests since React 16 #3199
Comments
I know React 16 needs that polyfill, my point is that create-react-app could provide it by default, taking the burden out of its users shoulders. For instance, it could depend on the raf package and change the test script in {
"scripts": {
"test": "react-scripts test --env=jsdom --setupTestFrameworkScriptFile=raf/polyfill",
},
} |
Great point! More to come on this soon, but happy to discuss further if you have some ideas! |
On the point of providing a Map and Set polyfill by default, my understanding is that Happy to be proven wrong, though. |
@lukerollans I'm not sure what you're referring to, we do not depend on or include Babel itself ( Polyfills wouldn't conflict with one another, so someone who uses |
I just double checked the source I linked to and I simply misread |
Ah, no problem! |
x-ref: #3200 |
@Timer i meant specifically for testing. Map and Set are already supported in Node 0.12+, so I think we can leave this issue just for CRA default test setup. |
@barraponto correct! but we target IE 9 and Map and Set are not available in IE <11, so we'll just kill two birds with one stone! 😄 |
fwiw, I know the current idea mentioned in various docs is to put this in global.requestAnimationFrame = function(callback) {
setTimeout(callback, 0);
}; ...but that doesn't seem to kill these warnings for me either after moving to 16. |
We'll figure something out soon. Sorry about that. This was the biggest release we ever did, there's also a new website we're launching today, and between all that there's a few kinks we still need to iron out. |
@holman FYI I had the same problem RE shim not working. The gotcha is that polyfill/shim needs to be in it's own file, and loaded before any dependencies. See jestjs/jest#4545 (comment). |
Nice! Yeah that fixed it for me. Thanks for the heads-up @jameslockwood. |
I have following file setupTest.js: import React from 'react' // React 16 Enzyme adapter // Make Enzyme functions available in all test files without importing // Fail tests on any warning global.requestAnimationFrame = function(callback) { but i still get the error: I i keep only works fine, if i put all of the above the error appers again... any idea what is happening? Thanks, |
It’s not an error. It is a warning. If you use Create React App, you can safely ignore it and nothing will happen. We’ll release a fix that makes it disappear soon. |
(The reason I think you’re getting it is because rAF is shimmed after Enzyme adapter is imported.) |
Thanks for your quick replay, I just realised I met you at a meeting organised by Sapient Nitro in London. My solution was to create src/tempPolyfills.js const raf = global.requestAnimationFrame = (cb) => {
setTimeout(cb, 0)
}
export default raf src/setupTests.js import raf from 'tempPolyfills'
import Enzyme, { shallow, render, mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import toJson from 'enzyme-to-json';
// React 16 Enzyme adapter
Enzyme.configure({ adapter: new Adapter() });
// Make Enzyme functions available in all test files without importing
global.shallow = shallow;
global.render = render;
global.mount = mount;
global.toJson = toJson;
// Fail tests on any warning
console.error = message => {
throw new Error(message);
}; Thanks |
Yep, that works! Again, sorry about this. I’ll look into it right after cutting 16.0.1 (which still needs a few more bugfixes to be ready). |
Adding
I instead did this and everything works: src/setupTest.js
... basically the same as @unutoiul answer. |
also the registerServiceWorker.js doesn't pass the eslint validation. |
That sounds odd. You shouldn't need to do this, Create React App already runs the test setup file with this name automatically. Can you remove this and check if it still works? |
@gaearon ah yes you're right! I'm pretty sure I tried this before and it didn't work which is why I added the location as an argument. |
Sweet. Again, I’m sorry this is still not resolved. I got sick with a stomach bug and have been slowly recovering this week. I’m mostly well now and expect to get to this in a couple of days. |
Hi Dan, what structure of the code you would recommend using to make RESTful API calls with react&redux? |
@unutoiul probably not the place for such questions but for making API calls, or dealing with side effects, you would want redux-thunk (Dan's project :p), or redux-sage. There's a lot of options tbh. |
Sadly @unutoiul solution does not work for me :(. The only difference is i'm using react-scripts-ts - TypeScript. tempPolyfill.ts
setupTests.ts
Any clues? |
Except it exits with a non-zero exit code. |
Can you provide a minimal example demonstrating this please? That sounds like a bug to me. It’s just a |
(If you configured your tests to fail on |
I have recently found the CI=true option and it's now exiting correctly. Thanks. |
Looking forward to the fix for this, but no pressure. Hope you're feeling better @gaearon. |
I think we'll fix this by updating to Jest version that already has a polyfill. |
it's possible when you don't want to work with older browser just turn off the warnings and errors on test ? or like android apps to specify the min. version supported ? or technically is not good idea? I think the idea to add polyfills when you dont' really need add more code to the build file ? |
Not worked for me with latest Create React App This is my solution:
setupTests.ts
|
This issue is starting to get noisy with potentially incorrect advice so I'm locking this. If you experience problems please file a new issue. Note that as of |
Is this a bug report?
Yes
Which terms did you search for in User Guide?
The issue is documented at https://facebook.github.io/react/docs/javascript-environment-requirements.html
Steps to Reproduce
create-react-app project
yarn test
Expected Behavior
I expected the testing to complete without warnings out-of-the-box (as it did pre-R16).
Actual Behavior
All tests pass, but prints message:
The text was updated successfully, but these errors were encountered: