| Item | Value |
|---|---|
| Framework | Jest 29 + @testing-library/react 16 |
| Test directory | __tests__/ |
| File pattern | __tests__/*.test.tsx |
| Mock directory | __mocks__/@auth0/auth0-spa-js.tsx |
| Test environment | jsdom (jest-environment-jsdom) |
| Coverage threshold | 100% branches / functions / lines / statements |
| Coverage exclusions | /__tests__/, index.tsx |
# All tests with coverage
npm test
# Single file
npx jest __tests__/auth-provider.test.tsx
# Watch mode
npx jest --watchThe default npm test suite is unit-only — no Auth0 tenant or network access required. All calls to Auth0Client go through the manual mock.
⚠️ These tests start real example apps (CRA, Next.js, Gatsby) and run Cypress smoke tests against a live Auth0 tenant. They are slow and require real credentials. Ask before running (see Boundaries in CLAUDE.md).
# Requires:
# CYPRESS_USER_EMAIL — test user email on your Auth0 tenant
# CYPRESS_USER_PASSWORD — test user password
# TEST_DOMAIN, TEST_CLIENT_ID, TEST_AUDIENCE — Auth0 app configuration
CYPRESS_USER_EMAIL=<email> CYPRESS_USER_PASSWORD=<pw> npm run test:integrationSee examples/README.md for example app setup instructions.
- Grouping:
describe('ComponentName / hookName', () => { ... }) - Naming:
it('should <behaviour> when <condition>', ...) - Async hooks: use
renderHook+waitForfrom@testing-library/react - Rendered components: use
render+screen+actfor event-driven state changes - URL cleanup:
afterEach(() => { window.history.pushState({}, document.title, '/'); })to restore URL state between redirect-related tests - Provider wrapping: import
createWrapper()from__tests__/helpers.tsxto wrap hooks inAuth0Providerwith sensible test defaults
The manual mock at __mocks__/@auth0/auth0-spa-js.tsx provides jest.fn() stubs for every Auth0Client method. Configure per-test behaviour with .mockResolvedValueOnce:
import { Auth0Client } from '@auth0/auth0-spa-js';
const clientMock = jest.mocked(new Auth0Client({ clientId: '', domain: '' }));
// Configure for a specific test scenario
clientMock.checkSession.mockResolvedValueOnce(undefined);
clientMock.getUser.mockResolvedValue({ sub: 'user123', name: 'Test User' });Do not replace the manual mock with inline jest.mock() — the shared file keeps all method stubs consistent and avoids re-declaring the full Auth0Client shape in every test file.
100% coverage is enforced by Jest. The coveragePathIgnorePatterns config excludes /__tests__/ and index.tsx (the re-export barrel). All new code added to other files under src/ must have branch, function, line, and statement coverage.