ava icon indicating copy to clipboard operation
ava copied to clipboard

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

Open OmgImAlexis opened this issue 5 years ago • 4 comments

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

OmgImAlexis avatar Sep 14 '19 03:09 OmgImAlexis

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.

novemberborn avatar Sep 15 '19 17:09 novemberborn

The second one sounds good.

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

OmgImAlexis avatar Sep 15 '19 22:09 OmgImAlexis

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.

novemberborn avatar Sep 16 '19 07:09 novemberborn

Popping in to lend my 👍 to this one, and both the suggestions on the last reply.

shellscape avatar Jun 01 '21 23:06 shellscape