Question about testing my OrderForm
I have an Order Form which I would like to test. So I have an OrderResource and the url to the form is:
admin/orders/create
I believe that this corresponds to: 'create' => Pages\CreateOrder::route('/create'),
So I wrote a test for this like so:
But when I run this I get:
Attempt to read property "form" on null.
at vendor/filament/forms/src/Testing/TestsForms.php:125 121▕ public function assertFormExists(): Closure 122▕ { 123▕ return function (string $name = 'form'): static { 124▕ /** @var ComponentContainer $form */ ➜ 125▕ $form = $this->instance()->{$name}; 126▕ 127▕ $livewireClass = $this->instance()::class; 128▕ 129▕ Assert::assertInstanceOf(MyCreateOrder class doesn't have a form property. I'm wondering where the $form property is set that renders the form when go to the aforementioned url How can I solve this? Thanks
Solution:Jump to solution
you didn't
login()
```php
it('Can only select suppliers related to the brand', function () {
login();
...18 Replies
I would appreciate it if someone can have a look at this and let me know what the problem could be. It has to do with testing forms
add
$this->get(OrderResource::getUrl('create'));
before livewire(CreateOrder::class) ...
This returns
can i see your test file?
Sure:
could you import the
CreateOrder
page and try?sure: But that gives me.
This to me sounds logic since my CreateOrder page doesn't have a form:
no, import the
CreateOrder
class in your test like
use App\Filament\Resources\OrderResource\Pages\CreateOrder;
I did so:
and what is the result? it should say something like
failed asserting that null matches expected ??
since you are not setting the supplier_id
and then asserting that it's set.This is the result:
Solution
you didn't
login()
L E G E N D ! ! ! 🔥 🔥 🔥
Thanks soo much!
np, cheers!
Actually I should do a beforeEach(login());
or use the
setUp()
method.
for more, test cases and ref, checkout the filament codebase itself.GitHub
filament/tests at 3.x · filamentphp/filament
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
Tnx!