skills/angular-developer/references/e2e-testing.md
Use E2E tests to cover critical user journeys in a real browser. Prefer the framework already configured in the Angular workspace, such as Cypress or Playwright.
Check package.json and angular.json for the project-specific command. Common patterns include:
npm run e2e
pnpm e2e
ng e2e
When the app must be built or served first, use the existing project scripts instead of inventing a parallel test entrypoint.
cypress/e2e/ or e2e/.describe('Login flow', () => {
it('redirects to dashboard on valid credentials', () => {
cy.visit('/login');
cy.get('[data-cy=email]').type('[email protected]');
cy.get('[data-cy=password]').type('password123');
cy.get('[data-cy=submit]').click();
cy.url().should('include', '/dashboard');
});
});
import {expect, test} from '@playwright/test';
test('redirects to dashboard on valid credentials', async ({page}) => {
await page.goto('/login');
await page.getByLabel('Email').fill('[email protected]');
await page.getByLabel('Password').fill('password123');
await page.getByRole('button', {name: 'Sign in'}).click();
await expect(page).toHaveURL(/dashboard/);
});
getByRole, getByLabel) or stable data-* attributes.