Ava: Improve error shown when tests finishes while throwsAsync / notThrowsAsync assertions remain pending

Created on 14 Sep 2019  Â·  3Comments  Â·  Source: avajs/ava

Description

Currently when you run a test with a non-awaited t.throwsAsync the only error shown is Error: Test finished, but an assertion is still pending. I'd love to see something similar to the TypeError thrown for todo tests that have an implementation.

Test Source

t.throwsAsync(async () => {
    await parseDomain();
}, 'Type must be one of [id,uuid,name], undefined given.');

Error Message & Stack Trace

  1 test failed [13:01:49]
  1 previous failure in test files that were not rerun

  parse-domain › allows lookup via name, id and uuid


  Error: Test finished, but an assertion is still pending

  Type `r` and press enter to rerun tests
  Type `u` and press enter to update snapshots

bug help wanted assertions

Most helpful comment

OK so to summarize:

  • As a first-pass improvement, update the messaging to explain that t.throwsAsync and t.notThrowsAsync assertions need to be awaited on
  • As a second-pass, print the line numbers and perhaps the context of all uses of those assertions within the test, to help users debug the problem

I'll also open an issue on our ESLint plugin.

All 3 comments

Could you elaborate on what message you'd like to see? Ironically t.throwsAsync and it's t.notThrowsAsync() counterpart are our only assertions that can even be pending, so it should be straight-forward to change the messaging here.

Or, going further, we should have the stack traces of where those assertions were started, so we could list which assertions may not have been awaited properly.

The second one sounds good.

Maybe also add a linting rule similar to the todo one?

OK so to summarize:

  • As a first-pass improvement, update the messaging to explain that t.throwsAsync and t.notThrowsAsync assertions need to be awaited on
  • As a second-pass, print the line numbers and perhaps the context of all uses of those assertions within the test, to help users debug the problem

I'll also open an issue on our ESLint plugin.

Was this page helpful?
0 / 5 - 0 ratings