Summer Sale! All accounts are 50% off this week.

bwrigley's avatar

Unit testing Vue Components that use Inertia functions

Hi Everyone,

I'd like to Unit tests my Vue components and I'm wondering what people currently suggest for a testing framework.

I'm using Dusk for e2e testing and phpUnit for Laravel unit testing, and I have been exploring Cypress for component testing but I'm not having much luck yet as I use many of the Inertia features.

I've watched many of Jeffrey's tutorials on Cypress but I can't find any that specifically cover testing components that use Inertia and I wonder if I should be looking at something like Jest instead and where better to ask than here :)

0 likes
1 reply
Napo7's avatar

Hi,

I also tried a bit to test my inertia pages from the vue side, but never managed to do it.

My bet is that we should probably extract inertia functionalities in composables, and then mock those composables ?

I've not tried recently , perhaps since Inertia 1.0 it's easier to test ? Last time I tried, I was facing errors about using the $page.props inside my layouts, which could probably be embedded in a useSomething.js component, and then be mocked.

Some ideas to try, if you've got some time to do so...

I might give it a try also, because I'm facing more and more regressions when making changes in my apps that are only back-end tested... And E2E testing is the last thing I want to turn to, since it's way slower than JS testing...

Please or to participate in this conversation.