title: Testing TypeORM repo find function with where option
body: <p>I am trying to test a catch error if a result is not found, using TypeORM <code>find</code> function against an entity, with an additional option of <code>where</code></p>
  <p>I have tried to mock the function however I cannot seem to mock the <code>where</code> bit of the function.</p>
  <p>service file</p>
  <pre><code>try {
      historicalTypes = await this.historicalMappingDataTypesRepo.find({
       where: {
            HistoricalTypes: 'Contracts',
          },
      });
  }
  catch (e) {
    if (e instanceof Error) {
      this.logger.error(`Historical mapping type contracts could not found: ${e.message}`, e.stack);
    } else {
      this.logger.error(`Historical mapping type contracts could not found: ${e}`);
    }
    return;
  }
  </code></pre>
  <p>test</p>
  <pre><code>const mockHistoricalTypes: HistoricalTypes[] = [
      {
        HistoricalTypeID: 1,
        HistoricalType: 'Contracts',
      },
  ];
  
  const mockHistoricalMappingTypesRepo = {
      find: ({where}) =&gt; Promise.resolve(mockHistoricalMappingTypes),
  };
  
  beforeAll(async () =&gt; {
      const module: TestingModule = await Test.createTestingModule({
        providers: [
          HistoricalMappingSchedulerService,
          {
            provide: HistoricalMappingSchedulerRepository,
            useValue: mockHistoricalMappingSchedulerRepository,
          },
          {
            provide: getRepositoryToken(HistoricalMappingTypes),
            useValue: mockHistoricalMappingTypesRepo,
          },
        ],
      }).compile();
      service = module.get&lt;HistoricalMappingSchedulerService&gt;(HistoricalMappingSchedulerService);
  });
  
  it('should throw an error when historical type id is not found', async () =&gt; {
      await mockHistoricalMappingTypesRepo.find({
        where: {
          HistoricalMappingType: 'Testing',
        },
      });
      const mockFn = () =&gt; service.ContractHistoricalMapping();
      expect(mockFn).toThrowError();
  });
  </code></pre>