title: Jest mock window.scrollTo
body: <p>My React component calls <code>window.scrollTo</code> and when I run my jest tests, they pass, but there is a console error:</p>
  
  <pre><code> console.error node_modules/jsdom/lib/jsdom/virtual-console.js:29
  Error: Not implemented: window.scrollTo
      at Object.&lt;anonymous&gt;.module.exports (/private/var/www/samplesite.com/node_modules/jsdom/lib/jsdom/browser/not-implemented.js:9:17)
      at Window.scrollTo (/private/var/www/samplesite.com/node_modules/jsdom/lib/jsdom/browser/Window.js:544:7)
      at scrollTo (/private/var/www/samplesite.com/back-end/utils/library.jsx:180:12)
      at commitHookEffectList (/private/var/www/samplesite.com/node_modules/react-dom/cjs/react-dom.development.js:17283:26)
      at commitPassiveHookEffects (/private/var/www/samplesite.com/node_modules/react-dom/cjs/react-dom.development.js:17307:3)
      at Object.invokeGuardedCallbackImpl (/private/var/www/samplesite.com/node_modules/react-dom/cjs/react-dom.development.js:74:10)
      at invokeGuardedCallback (/private/var/www/samplesite.com/node_modules/react-dom/cjs/react-dom.development.js:256:31)
      at commitPassiveEffects (/private/var/www/samplesite.com/node_modules/react-dom/cjs/react-dom.development.js:18774:9)
      at wrapped (/private/var/www/samplesite.com/node_modules/react-dom/node_modules/scheduler/cjs/scheduler-tracing.development.js:207:34)
      at flushPassiveEffects (/private/var/www/samplesite.com/node_modules/react-dom/cjs/react-dom.development.js:18822:5) undefined
  </code></pre>
  
  <p>I have tried mocking it in a few ways (both in the test itself and also in a jest <code>setupFiles</code> that gets called before each test) , but the console error will not go away:</p>
  
  <p>Attempt 1:</p>
  
  <pre><code>let window = {};
  window.scrollTo = jest.fn();
  </code></pre>
  
  <p>Attempt 2:</p>
  
  <pre><code>let scrollTo = jest.fn();
  Object.defineProperty(window, "scrollTo", scrollTo);
  </code></pre>
  
  <p>Attempt 3:</p>
  
  <pre><code>delete global.window.scrollTo;
  global.window.scrollTo = () =&gt; {};
  </code></pre>
  
  <p>Attempt 4:</p>
  
  <pre><code>global.window = {};
  global.window.scrollTo = () =&gt; {};
  </code></pre>
  
  <p>How can i get rid of this console error?  Thanks.</p>