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.

valid-expect-in-promise doesn't work with Promise.all

See original GitHub issue

I have a test case that relies on multiple promises being tested with Promise.all:

test('Resource loader: client usage', function () {
  expect.assertions(2);

  const quxLoader = ResourceLoader.create(['qux']);
  let promiseResolve;
  fetchResult = new Promise(resolve => promiseResolve = resolve);

  const promise1 = quxLoader.load();
  promise1.then(([x]) => expect(x.test).toBeTruthy());
  const promise2 = quxLoader.load();
  promise2.then(([x])  => expect(x.test).toBeTruthy());
  promiseResolve({test: true});

  return Promise.all([promise1, promise2]);
});

This causes the following eslint errors:

  68:3  error  Promise should be returned to test its fulfillment or rejection  jest/valid-expect-in-promise
  70:3  error  Promise should be returned to test its fulfillment or rejection  jest/valid-expect-in-promise

It’d be great if the rule would recognize Promise.all and considered it valid.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
SimenBcommented, Jan 28, 2019

Yeah, that’s a bug 🙂 Doesn’t seem like the rule handles Promise.all at all. PR welcome! 😀

0reactions
github-actions[bot]commented, Oct 10, 2021

🎉 This issue has been resolved in version 25.0.0-next.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

Promise.all doesn't return none of it's promises if one of them fail
If one of the URL's is invalid, the Promise.all doesn't return any of the results; in other words, all responses must be valid...
Read more >
Promise.allSettled() - JavaScript - MDN Web Docs
allSettled() method takes an iterable of promises as input and returns a single Promise . This returned promise fulfills when all of the...
Read more >
Error handling with promises - The Modern JavaScript Tutorial
Promise chains are great at error handling. When a promise rejects, the control jumps to the closest rejection handler.
Read more >
useEffect doesn't work as expected when Promise.all - Reddit
Because Promise.all does not sequentially call the functions your passing to it... they are already all fired. Promise.all just stops execution ...
Read more >
Promise.all - Bluebird JS
The promise's fulfillment value is an array with fulfillment values at respective positions to the original array. If any promise in the array...
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