Skip to content

[valid-expect-in-promise] Problem chaining .then's #405

@pladaria

Description

@pladaria

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');
});

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions