[valid-expect-in-promise] Problem chaining .then's
See original GitHub issueusing eslint-plugin-jest v22.15.2
This reports an error:
const fetch = url =>
Promise.resolve({
url,
text: () => Promise.resolve('text'),
});
// Error: Promise should be returned to test its fulfillment or rejection
test('valid-expect-in-promise', async () => {
const text = await fetch('url')
.then(res => res.text())
.then(text => text);
expect(text).toBe('text');
});
If I remove the last .then
, no error is reported:
// No eslint errors
test('valid-expect-in-promise', async () => {
const text = await fetch('url')
.then(res => res.text())
expect(text).toBe('text');
});
The following doesn’t report error, so perhaps the problem is not in chaining:
// No eslint errors
test('valid-expect-in-promise', async () => {
const text = await fetch('url')
.then(text => text)
.then(text => text);
expect(text).toBe('text');
});
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Promises chaining - The Modern JavaScript Tutorial
When a handler returns a value, it becomes the result of that promise, so the next .then is called with it. A classic...
Read more >Developers - [valid-expect-in-promise] Problem chaining .then's -
using eslint-plugin-jest v22.15.2. This reports an error: const fetch = url => Promise.resolve({ url, text: () => Promise.resolve('text'), }); ...
Read more >Using promises - JavaScript - MDN Web Docs
A Promise is an object representing the eventual completion or failure of an asynchronous operation. Since most people are consumers of ...
Read more >JavaScript Promise Tutorial: Resolve, Reject, and Chaining in ...
The main difference between Callback Functions and Promises is that we attach a callback to a Promise rather than passing it. So we...
Read more >JavaScript Promise Chain - The art of handling promises
You can throw an error from the .then() handler. If you have a .catch() method down the chain, it will handle that error....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@SimenB Cannot reproduce in 22.15.0, problem starts in 22.15.1
🎉 This issue has been resolved in version 25.0.0-next.6 🎉
The release is available on:
Your semantic-release bot 📦🚀