Created
February 11, 2026 19:05
-
-
Save claudiainbytes/7c09f3581c40fc1129a5112d7188c8eb to your computer and use it in GitHub Desktop.
Testing Page Object Pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // test-utils/page-objects/LoginPage.ts | |
| export class LoginPage { | |
| constructor(private user: ReturnType<typeof userEvent.setup>) {} | |
| async login(email: string, password: string) { | |
| await this.user.type(screen.getByLabelText(/email/i), email) | |
| await this.user.type(screen.getByLabelText(/password/i), password) | |
| await this.user.click(screen.getByRole('button', { name: /login/i })) | |
| } | |
| getErrorMessage() { | |
| return screen.queryByRole('alert') | |
| } | |
| async logout() { | |
| await this.user.click(screen.getByRole('button', { name: /logout/i })) | |
| } | |
| } | |
| // Test usando Page Object | |
| it('login flow', async () => { | |
| const user = userEvent.setup() | |
| const loginPage = new LoginPage(user) | |
| render(<App />) | |
| await loginPage.login('test@example.com', 'password123') | |
| expect(screen.getByText(/welcome/i)).toBeInTheDocument() | |
| expect(loginPage.getErrorMessage()).not.toBeInTheDocument() | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment