People searching “Laravel Http::fake” hit the real API from a Pest test because the URL in the fake did not match. The tests guide is the Inertia assertion. This page is the outbound stub.
TL;DR
- Http::fake stubs the outbound request.
- The Inertia test asserts the prop.
- It does not call the real host.
- Do not
Http::fake()with no argument and then assert the prop equals the real city’s name.
The fix#
use Illuminate\Support\Facades\Http;
Http::fake([
'https://maps.example/*' => Http::response(['label' => 'Rabat'], 200),
]);
$this->actingAs($user)
->get('/posts/create')
->assertOk();The controller calls Http::get('https://maps.example/place') and passes label as a prop. The test never opens a socket. If the pattern does not match, Http throws or calls the network, depending on Http::preventStrayRequests().
Http::preventStrayRequests();That line fails the test when a URL is not faked. Use it.
What to avoid#
Gotcha
Do not Http::fake() with no argument and then assert the prop equals the real city’s name. An empty fake returns 200 and an empty body. Do not disable TLS verification so the test can “just hit staging”.
FAQ#
How do I fake an HTTP call a Vue page depends on?
Http::fake stubs the outbound request. The Inertia test asserts the prop. It does not call the real host.
What goes wrong with Laravel Http::fake?
Many developers hit the real API from a Pest test because the URL in the fake did not match. Do not Http::fake() with no argument and then assert the prop equals the real city's name.



