Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: mixed-in expectation object causes IDE type errors #1166

Open
wand2016 opened this issue Jun 7, 2024 · 0 comments · May be fixed by #1168
Open

[Bug]: mixed-in expectation object causes IDE type errors #1166

wand2016 opened this issue Jun 7, 2024 · 0 comments · May be fixed by #1168
Labels

Comments

@wand2016
Copy link

wand2016 commented Jun 7, 2024

What Happened

With using a mixed-in expectation object, method chaining results in IDE type errors:

        expect($response->content())
            ->toBeJson()
            ->json()
            ->not()->toHaveKey('errors')
            ->toHaveKey('data')
            ->data->toEqual(...);
             // ^ IDE type error occurs

* @return self<TValue>

Suggested fix:

-    * @return self<TValue>
     * @return $this

Changing the PHPDoc return type to $this seems to be a better solution to avoid these IDE type errors.

How to Reproduce

        expect($response->content())
            ->toBeJson()
            ->json()
            ->not()->toHaveKey('errors')
            ->toHaveKey('data')
            ->data->toEqual([]);

image

The suggested fix above solves the problem:

image

Sample Repository

No response

Pest Version

2.x-dev

PHP Version

8.2.15

Operation System

Linux

Notes

pestphp/pest-plugin version is v2.1.1

@wand2016 wand2016 added the bug label Jun 7, 2024
@wand2016 wand2016 closed this as completed Jun 7, 2024
@wand2016 wand2016 reopened this Jun 7, 2024
@wand2016 wand2016 linked a pull request Jun 7, 2024 that will close this issue
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant