mercurius-js / mercurius

Implement GraphQL servers and gateways with Fastify
https://mercurius.dev/
MIT License
2.33k stars 234 forks source link

Several unit tests checking for errors would pass even if the error isn't thrown #995

Closed alcidesqueiroz closed 1 year ago

alcidesqueiroz commented 1 year ago

Several unit tests that check if a given error has been thrown are using the following approach:

try {
  await app.ready()
} catch (error) {
  t.equal(error.message, 'The expected error message')
}

The problem here is that, without using t.plan, these tests would pass even if the error wasn't thrown. And most tests using this pattern are not calling t.plan. My suggestion is to replace these try/catch occurrences with t.rejects, making the tests simpler and preventing these false positives.

FYI: @simoneb

mcollina commented 1 year ago

This would be a great refactor!

simoneb commented 1 year ago

Good catch