title: Jest in Bitbucket pipelines: TypeError: Cannot read property 'body' of null
body: <p>So I have some React component tests that are run on Bitbucket pipeline.
  Locally they work fine, but in CI I get the following error:</p>
  <pre><code>FAIL src/tests/components/exercise-steps/performance-only/drag-and-drop/drag-and-drop-exercise.test.tsx (5.815 s)
    ● DragAndDropExerciseUnwrapped Tests › expect to render DragAndDropExercise component with fractions and text
      TypeError: Cannot read property 'body' of null
         99 |   )?.innerHTML;
        100 |
      &gt; 101 |   const activeElement = document.getElementById(activeElementId);
            |         ^
        102 |   const correctionData =
        103 |     isStillOpen &amp;&amp; item.correctionData ? null : item.correctionData;
        104 |   const isDisabled: boolean =
        at getActiveElement (node_modules/react-dom/cjs/react-dom.development.js:1449:16)
        at getActiveElementDeep (node_modules/react-dom/cjs/react-dom.development.js:7767:17)
        at getSelectionInformation (node_modules/react-dom/cjs/react-dom.development.js:7800:21)
        at prepareForCommit (node_modules/react-dom/cjs/react-dom.development.js:10163:26)
        at commitRootImpl (node_modules/react-dom/cjs/react-dom.development.js:23085:29)
        at unstable_runWithPriority (node_modules/react-dom/node_modules/scheduler/cjs/scheduler.development.js:468:12)
        at runWithPriority$1 (node_modules/react-dom/cjs/react-dom.development.js:11276:10)
        at commitRoot (node_modules/react-dom/cjs/react-dom.development.js:22990:3)
        at performSyncWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:22329:3)
        at node_modules/react-dom/cjs/react-dom.development.js:11327:26
        at unstable_runWithPriority (node_modules/react-dom/node_modules/scheduler/cjs/scheduler.development.js:468:12)
        at runWithPriority$1 (node_modules/react-dom/cjs/react-dom.development.js:11276:10)
        at flushSyncCallbackQueueImpl (node_modules/react-dom/cjs/react-dom.development.js:11322:9)
        at flushSyncCallbackQueue (node_modules/react-dom/cjs/react-dom.development.js:11309:3)
        at scheduleUpdateOnFiber (node_modules/react-dom/cjs/react-dom.development.js:21893:9)
        at dispatchAction (node_modules/react-dom/cjs/react-dom.development.js:16139:5)
        at src/components/correction-requests/correction-request-with-marking-area/correction-request-with-marking-area.component.tsx:101:9
            at Array.map (&lt;anonymous&gt;)
        at src/components/correction-requests/correction-request-with-marking-area/correction-request-with-marking-area.component.tsx:99:39
  </code></pre>
  <p>First I thought maybe it is trying to select the element by id while to component is no longer mounted.. Turns out the stack trace is the same, even when I comment that code - so it would point to the same line, which is a comment.
  In general it seems kind of random when and if that error occurs - skipping unrelated tests sometimes helps, commenting lines that could not cause such an error sometimes helps too.</p>
  <p>The codebase has enzyme <em>and</em> RTL tests, but all tests that call this code use enzyme.
  I could not find anything helpful since all the issues regarding similar issues only apply to RTL and even if applied to not fix this issue.
  <a href="https://github.com/testing-library/react-testing-library/issues/661" rel="nofollow noreferrer">Issue 1</a>,
  <a href="https://github.com/facebook/react/issues/15691" rel="nofollow noreferrer">Issue 2</a></p>
  <p>Local reproduction is not possible even when running it in docker like Bitbucket pipelines.
  Thanks in advance!</p>