[Bug]: WebSocket client is not connected error thrown when using visit() in helper function
What Happened
In pest.php I expect to be able to write a helper method for logging in via the frontend, but it seems you cant use the visit() function in a helper method, as it then throws a WebSocket client is not connected when using the helper method in your test.
How to Reproduce
Create a helper method like this (simplified version)
function loginHelper()
{
return visit(frontendRoute('login'))
->type('email', '[email protected]')
->type('password', 'Password123');
}
Then use the helper in a test
it('Can visit something using helper', function () {
loginhelper()->assertSee('Hello World');
});
When running the test, you should see the WebSocket client is not connected. error
Sample Repository
No response
Pest Version
4.0.4
PHP Version
8.3
Operation System
macOS
Notes
Might seem weird why we do it like this, but its because our application is a more traditional SPA with token auth, so to get the tests to work we have to login via the frontend route, which works but the code is verbose, therefore it would be great if you could actually write a helper function that uses the visit function
Just as a note I have also tried with
function loginHelper()
{
return test()->visit(frontendRoute('login'))
->type('email', '[email protected]')
->type('password', 'Password123');
}
But that gives the same error
Related #1439