0

I mocking a function, and for some reason, the code is still running the original function, I made sure that the function is indeed mocked using isMockFunction,

import { getTables, getExportFiles } from 'rds-formatter';   
 jest.mock('rds-formatter', () => {
      return {
      ...jest.requireActual('rds-formatter'),
      getExportFiles: jest.fn(() => Promise.resolve('return something')),
    });

Now the thing is Im testing an asyncGenerator function

export async function *getTables(assetId: string, payload: Record<string, unknown>) {  
const { parquetFiles, tablesInfoFile } = await getExportFiles(s3Client, payload); 
return parquetFiles }

My test looks like this:

  it('', async () => {
console.log(jest.isMockFunction(getExportFiles)); //returns true
const data = getTables('gfsdg', payload)

expect((await data.next()).value).toBe('')
  });

The error I'm getting is s3Client.listObjectsV2 is not a function This error is from inside the function I'm trying to mock, I know this happens because I'm not passing a real client, but from my understanding the compiler shouldn't even go inside the mocked function, no?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
NadavT
  • 63
  • 4
  • 1
    Does this answer your question? [How to mock functions in the same module using Jest?](https://stackoverflow.com/questions/45111198/how-to-mock-functions-in-the-same-module-using-jest) – jonrsharpe Dec 05 '22 at 08:13
  • That is the answer, sort of.. I'm not a fan of changing the original code for unit testing, because it doesn't seem like the best solution if I wanna test a giant repo it would be tedious – NadavT Dec 05 '22 at 08:56

0 Answers0