Skip to content

Add unit tests with Jest and React Testing Library for core application modules#10

Open
bigweavergammainternal[bot] wants to merge 1 commit intomainfrom
add-unit-tests-20260217-003832
Open

Add unit tests with Jest and React Testing Library for core application modules#10
bigweavergammainternal[bot] wants to merge 1 commit intomainfrom
add-unit-tests-20260217-003832

Conversation

@bigweavergammainternal
Copy link
Copy Markdown

This pull request was generated by @kiro-agent 👻

Comment with /kiro fix to address specific feedback or /kiro all to address everything.
Learn about Kiro autonomous agent


Notes

This PR introduces a comprehensive unit testing setup for the amplify-next-template repository using Jest and React Testing Library. The goal is to establish a solid testing foundation that covers the core application components and Amplify backend configuration modules, enabling confidence in future refactoring and feature development.

What changed and why

Testing framework setup:

  • Configured Jest with next/jest for seamless Next.js integration, using jsdom test environment for DOM-based component testing.
  • Added jest.config.ts with module name mapping for path aliases (@/) and .js extension resolution.
  • Added jest.setup.ts to import @testing-library/jest-dom custom matchers globally.
  • Added a test script to package.json for running the test suite via npm test.

New dev dependencies:

  • jest, jest-environment-jsdom, @types/jest — Core testing framework
  • @testing-library/react, @testing-library/jest-dom, @testing-library/user-event — React component testing utilities
  • ts-node — TypeScript support for Jest config

Test coverage for application components:

Module Tests
app/page.tsx (App) Rendering, Todo creation via prompt, Todo deletion, Todo listing via subscription, state updates from subscription emissions, empty state handling
app/layout.tsx (RootLayout) Children rendering, HTML structure with <html> and <body> tags
amplify/data/resource.ts Schema definition validation, Todo model content field, authorization rules (allow.owner())
amplify/auth/resource.ts Auth resource export, defineAuth invocation, email login configuration
amplify/backend.ts defineBackend invocation, auth and data resource wiring

All AWS Amplify modules are tested using mocks (jest.mock) and jest.isolateModules to ensure clean module state between tests, avoiding side-effect leakage.

Testing

  • All tests pass successfully with npm test.
  • Tests use mocked AWS Amplify client (generateClient) and backend definition functions to avoid external dependencies.
  • Component tests validate user interactions (button clicks, prompt dialogs) and reactive state updates through subscription callbacks.

- Set up Jest with React Testing Library for testing Next.js components
- Add jest.config.ts with next/jest integration, jsdom environment, and module path mapping
- Add jest.setup.ts with @testing-library/jest-dom matchers
- Add test script to package.json

Test coverage:
- app/page.tsx: Rendering, todo creation, todo listing, state management with mocked generateClient
- app/layout.tsx: Children rendering, HTML structure, font class application
- amplify/data/resource.ts: Schema definition, Todo model fields, authorization rules
- amplify/auth/resource.ts: Auth resource definition, email login configuration
- amplify/backend.ts: Backend configuration with auth and data resources

Dependencies added:
- jest, jest-environment-jsdom, @types/jest
- @testing-library/react, @testing-library/jest-dom, @testing-library/user-event
- ts-node

Also add Dockerfile and .dockerignore for development/testing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant