From fe4dc744d74bf7e82b5ce5293106871c5146bfb0 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Sat, 28 Oct 2017 17:57:27 +0100 Subject: [PATCH] Polyfill rAF in test environment (#3340) --- packages/react-scripts/config/polyfills.js | 6 ++++++ packages/react-scripts/package.json | 1 + 2 files changed, 7 insertions(+) diff --git a/packages/react-scripts/config/polyfills.js b/packages/react-scripts/config/polyfills.js index 673fb8399b4..8d97fb4ac39 100644 --- a/packages/react-scripts/config/polyfills.js +++ b/packages/react-scripts/config/polyfills.js @@ -22,3 +22,9 @@ require('whatwg-fetch'); // Object.assign() is commonly used with React. // It will use the native implementation if it's present and isn't buggy. Object.assign = require('object-assign'); + +// In tests, polyfill requestAnimationFrame since jsdom doesn't provide it yet. +// We don't polyfill it in the browser--this is user's responsibility. +if (process.env.NODE_ENV === 'test') { + require('raf').polyfill(global); +} diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index 2b793a35dab..1eedb9e99aa 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -48,6 +48,7 @@ "postcss-flexbugs-fixes": "3.2.0", "postcss-loader": "2.0.6", "promise": "8.0.1", + "raf": "3.4.0", "react-dev-utils": "^4.1.0", "style-loader": "0.19.0", "sw-precache-webpack-plugin": "0.11.4",