question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Too aggressive in declaring the test "finished"

See original GitHub issue

The following works in 0.18.2:

test(t => {
	t.notThrows(new Promise(resolve => {
		setTimeout(() => {
			t.pass();
			resolve();
		}, 100);
	}));
});

On master, it fails with:

Assertion passed, but test has already ended

We should wait until all pending assertions have resolved before declaring a test “finished” and throwing when new assertions show up.

Adding a call to t.plan() causes it to behave oddly going all the way back (we even added a test solidifying this odd behavior in #360):

test(t => {
   t.notThrows(new Promise(resolve => {
       t.plan(2);
       setTimeout(() => {
         t.pass();
         resolve();
       }, 100);
   }));
});

The above fails with:

Planned for 2 assertions, but got 1.

Similar results for as far back as I tested.

I think we should allow for added assertions, as long as we still have pending assertions. When t.plan is used, I don’t think we should check for too few assertions until we’ve drained all pending assertions.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
sindresorhuscommented, Apr 3, 2017

I already always do:

test(async t => {
  await t.throws(…);
});

Instead of:

test(t => {
 t.throws(…);
});

The former is clearer by being explicitly async. It’s easier to add stuff after the throws assertion and get expected order of execution. You can get the error without having to change things around. Simpler to document.

1reaction
jamestalmagecommented, Apr 3, 2017

How would we enforce that? Can you tell a function is async before calling it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Joe Root century sets up aggressive declaration in Antigua
Joe Root scored his 24th Test century to go second on England's all-time list before a brave declaration left the West Indies chasing...
Read more >
Dhoni's declaration leaves Bridgetown Test nicely poised | New ...
It is a matter of debate whether India should have been more aggressive with the bat on Day Four when Rahul Dravid and...
Read more >
The Brilliance and Weirdness of ChatGPT - The New York Times
But there are risks to testing in public, including the risk of backlash if users deem that OpenAI is being too aggressive in...
Read more >
UPDATE 2-Cricket-Test Series Bangladesh v Pakistan ...
UPDATE 2-Cricket-Test Series Bangladesh v Pakistan scoreboard ... All quotes delayed a minimum of 15 minutes. See here for a complete list of ......
Read more >
TikTok's Problem Child Has 7 Million Followers and One ...
Her mom, Maria Ulacia, found it funny, too. ... in a post that generated 3 million views, declaring in a caption “these are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found