getTable() on null on Pest Test
Hi all
I need some help with some table tests if anyone can spare a few minute please.
I am getting:
I must say I am very new to tests. I have used the example on the filamentdocs https://filamentphp.com/docs/3.x/tables/testing
The page itself loads okay and shows results.
Any advice?
EDIT: another example:
gives
7 Replies
it seems any table test fails for some reason
Does ->assertSuccessful() work?
Yes it does. It just seems when I need to test the data on the table I get problems
Almost like the data is not being passed into the table for the test
I have nothing fancy going on within my table. The factory works and tested looking at table normally. Just the tests not working
You didn't log in any user. Usually those weird errors happen when you are not logged in or you are targeting the wrong Panel
I’ll give this a go and report back. Thanks for the tip to check. I thought I had a global user logged in but I could be wrong. Very new to tests.
Out of interest, is it advised to have a testing database rather than my local dev one ? And use the refresh database trait. ? Many thanks
So I figured out my issues.
1) needed a user as you said
BUT
2) my app service provider defines the gates and each time RefeeshDatabase was run it would loose those each test creates a user with a new permission.
Took me an age to figure it out but now I just run the gates again after every user is created per test and it’s okay. Maybe this would be easier with spaties permission package I’m not sure. I just built a light weight one myself.
Used this in my Pest.php file on a recent project, use spatie permissions, but maybe some insight.
Seeding the db for tests is possible too, but I like the isolation of being explicit with the data associated with the test.
Thank you for that. I have a similar setup.
I did start with seeding which was a hassle to setup anyway with refresh database trait. But I switched to creating the explicit data per test which I prefer now as well. Appreciate the tips.
Tests are a whole new world. It is quite addictive seeing all that green passes though haha