title: Mock Lerna scoped module with Jest
body: <p>I have a monorepo setup with Lerna. The project is compiled with tsc and the tests are ran with ts-jest v27.</p>
  <p>One of the files that I'm trying to test has this code:</p>
  <pre class="lang-js prettyprint-override"><code>import { someFunction } from '@local/package/dist/something'
  
  const someLogic = () =&gt; {
    someFunction()
  }
  </code></pre>
  <p><code>@local/package</code> is a local monorepo package symlinked by Lerna.</p>
  <p>I need to mock <code>someFunction</code>.</p>
  <p>Things I've tried:</p>
  <hr />
  <pre class="lang-js prettyprint-override"><code>jest.mock('@local/package/dist/something')
  </code></pre>
  <p>Has zero effect, the original file is still called.</p>
  <hr />
  <pre class="lang-js prettyprint-override"><code>import * as something from '@local/package/dist/something'
  
  jest.spyOn(something, 'someFunction')
  </code></pre>
  <p>Zero effect.</p>
  <hr />
  <pre class="lang-js prettyprint-override"><code>import * as something from '@local/package/dist/something'
  something.someFunction = jest
        .fn()
        .mockReturnValue(123)
  </code></pre>
  <p>Leads to <code>TypeError: Cannot set property &quot;someFunction&quot; of #&lt;Object&gt; which has only a getter</code></p>
  <hr />
  <p>jest.config.js:</p>
  <pre><code>{
  moduleNameMapper: {
      '(.*)something(.*)': '&lt;rootDir&gt;/src/somethingMock.js',
    }
  }
  </code></pre>
  <p>Zero effect.</p>
  <hr />
  <p>I tried to create '<strong>mocks</strong>/@local/package/dist/something.js' next to package.json of the package inside which I have tests.<br />
  Zero effect.</p>
  <hr />
  <p>I'm tired and I need help.... What am I doing wrong?</p>