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] Problem chaining .then's

See original GitHub issue

using 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:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
pladariacommented, Aug 29, 2019

@SimenB Cannot reproduce in 22.15.0, problem starts in 22.15.1

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

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 >

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