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.

t.notThrows(promise) should return an "empty" promise

See original GitHub issue

This is as expected:

const value = Symbol()
t.notThrows(() => value) === undefined

However:

const value = Symbol()
(await t.notThrows(Promise.resolve(value))) === value

t.notThrows(promise) should return a promise, but for an undefined value.

The offending line is at https://github.com/avajs/ava/blob/dcdfbee689e1538420f5793bbaca09c7e78ddedd/lib/assert.js#L124.

The Flow and TypeScript definitions should be updated too:

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
novemberborncommented, Feb 18, 2017

IMO the parallel should be with the the form of notThrows that is passed a function:

const val = t.notThrows(() => ({foo: 'bar'}))
t.deepEqual(val, {foo: 'bar'})

Is that a sensible thing to do, or is it not? Currently it doesn’t work, and we should resolve that inconsistency one way or the other.

0reactions
sindresorhuscommented, Feb 18, 2017

I would rather say:

const prom = getProm();
await t.notThrows(prom);
t.is(typeof (await prom), 'string');

vs

const val = await t.notThrows(getProm());
t.is(typeof val, 'string');

I think the former, while a tiny bit more verbose, is much clearer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Returning empty promise - javascript - Stack Overflow
For this input @Input() callback: () => Promise<null>;. there is no guarantee that it's assigned to proper value.
Read more >
Empty Promises: Dos and Don'ts of ES6 Promises
What follows, are three tips for using promises more effectively. Chain, don't nest. When I first started playing with promises, I found myself ......
Read more >
Should.js API Documentation
Assert given promise will be fulfilled with some expected value (value compared using .eql). Result of assertion is still .thenable and should be...
Read more >
Behavior of empty promises in Node.js | by Elena Sharovar
Dear Node.js I did not expect this: if we do await [number] output is as expected: (async function main() { console.log('STARTED')
Read more >
Assert | Node.js v19.3.0 Documentation
All errors thrown by the node:assert module will be instances of the AssertionError ... doesNotReject() will return a rejected Promise with that error....
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