Skip to content

Exception from ArticleRepository is not tested #162

@Seb-C

Description

@Seb-C

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions