title: How to suppress window.function calls in a node context, e.g. Not implemented: window.scrollTo
body: <p>A coworker implemented a ScrollToTop component, which has this:</p>
  
  <pre><code>componentDidMount() {
      window &amp;&amp; window.scrollTo &amp;&amp; window.scrollTo(0, 0)
  }
  </code></pre>
  
  <p>To simply scroll a page to the top in some circumstances.</p>
  
  <p>However, when running tests, the tests periodically error with <strong>Not implemented: window.scrollTo</strong> (full error stack at bottom).</p>
  
  <p>I get that window.scrollTo doesn't exist in a node context, or in the jest tests.  How can I suppress the attempt to scroll in non-browser contexts?  Or how should I handle this global in jest?</p>
  
  <pre><code>console.error node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/virtual-console.js:29
    Error: Not implemented: window.scrollTo
        at module.exports (/src/argos-r/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/browser/not-implemented.js:9:17)
        at /src/argos-r/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/browser/Window.js:594:7
        at ScrollToTop.scrollTo [as componentDidMount] (/src/argos-r/src/components/ScrollToTop.js:6:45)
        at commitLifeCycles (/src/argos-r/node_modules/react-dom/cjs/react-dom.development.js:17334:22)
        at commitAllLifeCycles (/src/argos-r/node_modules/react-dom/cjs/react-dom.development.js:18736:7)
        at HTMLUnknownElement.callCallback (/src/argos-r/node_modules/react-dom/cjs/react-dom.development.js:149:14)
        at invokeEventListeners (/src/argos-r/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:193:27)
        at HTMLUnknownElementImpl._dispatch (/src/argos-r/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:119:9)
        at HTMLUnknownElementImpl.dispatchEvent (/src/argos-r/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:82:17)
        at HTMLUnknownElementImpl.dispatchEvent (/src/argos-r/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/nodes/HTMLElement-impl.js:30:27) undefined
  console.error node_modules/react-dom/cjs/react-dom.development.js:506
  </code></pre>