Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception from ArticleRepository is not tested #162

Open
Seb-C opened this issue Oct 13, 2021 · 0 comments
Open

Exception from ArticleRepository is not tested #162

Seb-C opened this issue Oct 13, 2021 · 0 comments

Comments

@Seb-C
Copy link
Contributor

Seb-C commented Oct 13, 2021

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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant