title: ReactJS and jest: how to use a mock value for element.offsetWidth?
body: <p>I have a component that programmatically creates a span element and adds text to it, then checks for its <code>offsetWidth</code>. Within my tests this value is 0. I would like to know how I can "force" it to another arbitrary value for testing.</p>
  
  <p>I tried with the following with no avail:</p>
  
  <pre><code>Object.defineProperty(HTMLElement.prototype, 'offsetWidth', { configurable: true, value: 500 })
  </code></pre>
  
  <p>Can anyone point me to the right direction? Thanks!</p>
  
  <p>Github: <a href="https://github.com/sickdyd/react-dynamic-badge" rel="nofollow noreferrer">https://github.com/sickdyd/react-dynamic-badge</a></p>
  
  <p>This is a link to the test file for the component: <a href="https://github.com/sickdyd/react-dynamic-badge/blob/master/src/test/__test__/DynamicBadge.test.js" rel="nofollow noreferrer">https://github.com/sickdyd/react-dynamic-badge/blob/master/src/test/<strong>test</strong>/DynamicBadge.test.js</a></p>