I'm trying to add blade directives for my Laravel package.
Everything is fine but on testing stage, I'm getting this error:
1) MahbodHastam\UserWallet\Tests\Feature\BladeTest::show_user_wallet_balance
InvalidArgumentException: View [userWalletBalance] not found.
Should I put $this->loadViewsFrom(...)
in the service provider?
View path: /tests/resources/views/userWalletBalance.blade.php
Test path: /tests/Feature/BladeTest.php
I also tried to move the resources
directory into Feature
directory (beside the BladeTest.php
) but got the same error.
This is my code on BladeTest.php
:
public function show_user_wallet_balance() {
$wallet = UserWallet::getWallet(wallet_id: 1);
$this->assertEquals('1000', $this->renderView('userWalletBalance', ['wallet' => $wallet]));
}
protected function renderView($view, $with) {
Artisan::call('view:clear');
return trim((string) view($view)->with($with));
}
I fixed it :D
Instead of loading views from files, I used the
InteractsWithViews
trait (which is on theIlluminate\Foundation\Testing\Concerns
namespace) to render the blade like the code below: