[Bug]: Browser plugin - assertUrlIs does not follow documentation
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 11.7k
- Forks
- 538
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 8
Description
What Happened
When using assertUrlIs() function on a browser page, the docs state you can use it as follows:
->assertUrlIs('/login');
But you cannot use it like this because the regex is errorneously prepending the ^ character, this means the full URL must start with /login with nothing preceding it. This makes the test always fail for example:
Actual URL [http://127.0.0.1:48701/login] does not equal expected URL [/login].
Failed asserting that 'http://127.0.0.1:48701/login' matches PCRE pattern "/^\/login$/u".
For this to work currently, you have to use the full URL inside your test, which is obviously silly due to the fact that the port number may always change between runs.
Removing the ^ preceding character does fix this issue.
How to Reproduce
Install a fresh Laravel app, install Pest and Pest Browser Plugin, then add a test which asserts what the URL is (e.g. ->assertUrlIs('/login');), Make sure the test would pass (make your app render that URL correctly and visit that page)
Run the test and see that it fails.
Sample Repository
No response
Pest Version
4.3.1
PHP Version
8.4.16
Operation System
Linux
Notes
pestphp/pest-plugin-browser version v4.2.1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/Api/Concerns/MakesUrlAssertions.php at the linked URL assertion logic, then reproduce the documented assertUrlIs('/login') example in a fresh Laravel app using the browser plugin. Confirm the test works with the generated host and port, and add or update coverage for the relative URL case before running the relevant browser-plugin tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100