Why are you creating a view?
You can send a request and then see whether your app is acting correctly to your request or not.
$this->get('/your/route/url')->assertSee('Shipping');
Summer Sale! All accounts are 50% off this week.
Hi guys,
I am facing an issue with feature tests and our views. Here is a sample of header view which is part of the whole layout:
<header class="{{ $headerClass ?? '' }}">
@if (Route::current()->getName() == 'index')
@include('frontend.eshop._parts.header.header_top_banner',['banner' =>
isset($banners['topBanner']) ?
$banners['topBanner'] :
null])
@endif
</header>
Here is my simple test where I wanna test if the view has some text int title:
public function test_delivery_and_payment_view_can_be_rendered()
{
$service = new UserOrderMethodsSelectionService();
$methodsService = new OrderSelectionMethodsService();
$shippingTypes = EshopShippingType::with('currentLangTranslation', 'activeConditions', 'shippingType.currentLangTranslation')->activeTypesForCurrentEshop()
->get();
$pickupSpots = Store::activeForCurrentEshopWithAddress()->get();
$selection = $service->getUserOrderMethodsSelections();
$validCombinations = $methodsService->getValidShippingPaymentCombinations();
$paymentTypes = $methodsService->retrievePaymentTypes();
$view = $this->view(app()->eshop['view'] . 'cart.delivery', compact(['shippingTypes', 'selection', 'pickupSpots', 'paymentTypes', 'validCombinations']));
$view->assertSeeText('Shipping');
}
So basically I am sending everything that is needed for that view. However due to the fact that I am checking @if (Route::current()->getName() == 'index') in the header.blade.php it crashes with error:
Call to a member function getName() on null
I guess it's because the test does not have route of course. I have tried Route::current()?->getName() == 'index') but no luck. Any suggestions how to improve this so I can test this view as well as others? You know header is visible on most views so if i want to test them it will be the same scenario.
Thanks
Why are you creating a view?
You can send a request and then see whether your app is acting correctly to your request or not.
$this->get('/your/route/url')->assertSee('Shipping');
Please or to participate in this conversation.