Core Concepts

Handling Exceptions or Errors

Testing Mocks with Exceptions or Errors

describe('test suites', () => {
  it('test', async () => {
    const typeorm = new MockTypeORM()
    typeorm.onMock(User).toReturn(new Error(), 'find')

    const userRepo = dataSource.getRepository(User)

    await expect(userRepo.find()).rejects.toThrowError()
  })
})

In the toReturn() function, instead of adding mock data, we add an error. When the find() function is called, it will throw an error, and we expect this in our test assertion.

Previous
Advanced Mocking