title: How to mock nanoid for testing?
body: <p>I'm trying to mock nanoid for my testing but it doesn't seem to be working.</p>
  <p>my function</p>
  <pre><code>  public async createApp(appDto: ApplicationDto): Promise&lt;string&gt; {
      const appWithToken = { ...appDto, accessToken: nanoid() };
      const application = await this.applicationModel.create(appWithToken);
  
      return application.id;
    }
  </code></pre>
  <p>My test:</p>
  <pre><code>  beforeEach(() =&gt; {
      mockRepository.create.mockResolvedValueOnce({ id: mockId });
    });
  
    test(&quot;creates application and returns an id&quot;, async () =&gt; {
      const mockAppDto: ApplicationDto = { email: &quot;123@mock.com&quot; };
      const application = await applicationService.createApplication(mockAppDto);
  
      expect(mockRepository.create).toHaveBeenCalledWith(mockAppDto); //how do I mock the nanoid here?
      expect(application).toBe(mockId);
    });
  </code></pre>
  <p>So basically I'm struggling to figure out how to mock the nanoid which is generated inside the function.</p>
  <p>I've tried the following at the top of the file:</p>
  <pre><code>jest.mock('nanoid', () =&gt; 'mock id');
  </code></pre>
  <p>however it doesn't work at all.</p>
  <p>Any help would be appreciated!</p>