nestjs-starter-rest-api icon indicating copy to clipboard operation
nestjs-starter-rest-api copied to clipboard

Exception from ArticleRepository is not tested

Open Seb-C opened this issue 2 years ago • 0 comments

In this test: https://github.com/monstar-lab-oss/nestjs-starter-rest-api/blob/master/src/article/repositories/article.repository.spec.ts#L51

I think that this test does not work as expected, because if the repository does not throw an exception, the assertion will not be executed at all.

I think the right pattern would be like this:

let gotException: any = null
try {
  await repository.foo()
} catch (e) {
  gotException = e
} finally {
  expect(gotException).not.toBe(null);
  expect(gotException.constructor).toBe(NotFoundException);
}

Seb-C avatar Oct 13 '21 08:10 Seb-C