nestjs-starter-rest-api
nestjs-starter-rest-api copied to clipboard
Exception from ArticleRepository is not tested
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);
}