Playing
01. Introduction and demo

Transcript

00:00
One option for testing Inertia apps is using end-to-end tests. These types of tests physically open a browser and interact with the page and this gives you the confidence that your application is working as expected, particularly when you have apps like Inertia-based apps where you're going to have lots of
00:19
JavaScript interactions. So to get started with end-to-end testing in Inertia, we're going to use the official Laravel Dusk package. This gives us a complete API for headlessly opening up a browser,
00:32
going ahead and interacting with elements and then of course performing assertions, making sure that things have gone the way that we want them to. There are other options like Cypress, but I've found Dusk the easiest to work with since it nicely integrates with Laravel.
00:47
Okay, let's take a look at a demo of the tests that we're going to be writing here and we're going to keep extending the course to add more. So to run our tests, we're going to use phpArtisan PEST and Dusk. Now when I run this, this is going to go through
01:01
and it's going to open up a browser. Obviously we can't see this at the moment and it's going to go through and we're going to see any failures, any things that have passed and then of course we'll get a nice summary at the end.
01:13
Now I've included a failing test in there. That's a little bit later when we're going to look at pushing this up to GitHub Actions, which we're also going to be covering in the course. So you can add this as part of your continuous integration flow.
01:26
But for now, let's go ahead and just look at what this looks like behind the scenes. So I'm actually going to go ahead and provide the browse option here. What this will do is it will open up a browser window and it will actually show us very, very slowly what the page is actually doing here.
01:40
So we're going through, we're creating tasks in this example application, we're deleting tasks, we're doing all sorts of things. That is generally going on behind the scenes unless we use the browse option. So in this course, we're going to cover 80% of what you need to know about Dusk
01:56
and we're going to slowly build up this task list application. Once we're done, you'll be able to start writing solid end-to-end tests for flows throughout your application that aren't possible with traditional feature or unit tests within Laravel.
02:11
We will be really careful and I'm going to give you a lot of advice that I have discovered along the way while writing end-to-end tests. We're going to make these tests super solid so they don't break if a piece of text changes or a button label changes on the page.
02:26
And we're also going to talk about probably when not to use end-to-end tests. So there's a lot to cover here, but let's get over to the first few episodes and the most important, which is setting up Laravel Dusk and making sure it's running and configured smoothly.

Episode summary

Welcome to the course! In this intro episode, we kick things off by talking about testing Inertia apps with end-to-end (E2E) tests. E2E tests are awesome for making sure your app—especially ones with lots of JavaScript, like those built with Inertia—is working the way it should for your users.

We’re going to use Laravel’s official Dusk package to do this. Dusk can open a browser (either headless or visible), interact with your app just like a real user would, and make sure everything is behaving. There’s a brief chat about other testing tools like Cypress, but we’re sticking with Dusk because it plays so nicely with Laravel.

Then I give a quick demo of how these tests work, showing PHPUnit (with Pest) and Dusk running tests against a task list app. You’ll see how the test browser creates tasks, deletes tasks, and more. We'll even play around with some failing tests to see how errors show up—a sneak peek at how this all works in continuous integration with GitHub Actions (that's coming later).

Throughout the course, we’re aiming to cover about 80% of the Dusk features you’ll actually need in real life, and I promise to share tons of practical tips and Gotchas I’ve learned so you’ll write robust tests (that don’t break if you just change a button label, for example).

Finally, I’ll touch on when not to bother with E2E tests—super important! Next up: we’ll dive straight into setting up Dusk so you can follow along. Let’s go!

Episode discussion

No comments, yet. Be the first!