pestphp / pestphp/pest

[Bug]: Browser plugin - assertUrlIs does not follow documentation

Open Beginner friendly
#1,607 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.