Summary
This chapter briefly looked at the kinds of tests you’ll need for testing authentication.
Playwright end-to-end tests should check the login flows, both successful and unsuccessful. They should also make use of fake credentials where possible and ensure that any routes are accessible only by authenticated users who are logged in using a test.beforeEach
call.
Vitest tests for authenticated routes work differently. They focus on the session
object that SvelteKit returns: does it have a valid value or not?
While this covers the basics, most applications will have much more complex needs: for example, your application might have individual data stores for each user, not just one global data store such as our Birthdays application.
The Playwright website contains good documentation on how to test specific patterns, such as having multiple user roles interact within one test. That can be found at https://playwright.dev/docs/auth.
In the next chapter, we’...