|
| 1 | +- Pest v4 is a huge upgrade offering: browser testing, smoke testing, visual regression testing, test sharding, faster type coverage, and profanity checking. |
| 2 | +- Browser testing is incredibly powerful and useful for this project. |
| 3 | +- Use the `search-docs` tool for detailed guidance on utilising these features. |
| 4 | + |
| 5 | +## Browser testing |
| 6 | +- You can use Laravel features like `Event::fake()`, `assertAuthenticated()`, and model factories within browser tests, as well as `RefreshDatabase` (when needed) to ensure a clean state for each test. |
| 7 | +- Test on multiple browsers (Chrome, Firefox, Safari). |
| 8 | +- Test on different devices and viewports (like iPhone 14 Pro, tablets, or custom breakpoints). |
| 9 | +- Switch color schemes (light/dark mode). |
| 10 | +- Interact with the page (click, type, scroll, select, submit, drag-and-drop, touch gestures, etc.). |
| 11 | +- Take screenshots or pause tests for debugging. |
| 12 | + |
| 13 | +@verbatim |
| 14 | +<code-snippet name="Pest browser test example" lang="php"> |
| 15 | +it('may reset the password', function () { |
| 16 | + Notification::fake(); |
| 17 | + $this->actingAs(User::factory()->create()); |
| 18 | + |
| 19 | + $page = visit('/sign-in') // visit on a real browser... |
| 20 | + ->on()->mobile() // or ->desktop(), ->tablet(), etc... |
| 21 | + ->inDarkMode(); // or ->inLightMode() |
| 22 | + |
| 23 | + $page->assertSee('Sign In') |
| 24 | + ->assertNoJavascriptErrors() // or ->assertNoConsoleLogs() |
| 25 | + ->click('Forgot Password?') |
| 26 | + ->fill('email', ' [email protected]') |
| 27 | + ->click('Send Reset Link') |
| 28 | + ->assertSee('We have emailed your password reset link!') |
| 29 | + |
| 30 | + Notification::assertSent(ResetPassword::class); |
| 31 | +}); |
| 32 | +</code-snippet> |
| 33 | +@endverbatim |
| 34 | +@verbatim |
| 35 | +<code-snippet name="Pest smoke testing example" lang="php"> |
| 36 | +$pages = visit(['/', '/about', '/contact']); |
| 37 | +$pages->assertNoJavascriptErrors()->assertNoConsoleLogs(); |
| 38 | +</code-snippet> |
| 39 | +@endverbatim |
0 commit comments