Skip to content

Add comprehensive unit test suite with Jest for Next.js + Amplify app#8

Open
bigweavergammainternal[bot] wants to merge 1 commit intomainfrom
amplify-next-template-dev-20260216-200255
Open

Add comprehensive unit test suite with Jest for Next.js + Amplify app#8
bigweavergammainternal[bot] wants to merge 1 commit intomainfrom
amplify-next-template-dev-20260216-200255

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


Problem

The amplify-next-template repository has no testing framework or unit tests, leaving the codebase without automated quality assurance. This gap makes it harder to catch regressions, validate behavior of Amplify integrations, and maintain confidence during future development.

Solution

Set up a complete Jest-based testing infrastructure and add comprehensive unit tests covering all key modules in the project.

Testing Framework Setup

  • Jest with ts-jest transform for TypeScript/JSX support
  • jsdom test environment for React component testing
  • @testing-library/react and @testing-library/jest-dom for idiomatic component assertions
  • Module name mappers for CSS, static files, and @/ path aliases
  • Transform ignore patterns configured to allow @aws-amplify and aws-amplify modules
  • jest.setup.ts for global test matchers
  • Mocks for CSS (styleMock.ts) and static files (fileMock.ts)

Unit Tests Added

Module File Coverage
App Component (app/page.tsx) __tests__/app/page.test.tsx Rendering, initial state, observeQuery subscription & state updates, createTodo via prompt, UI interactions
RootLayout (app/layout.tsx) __tests__/app/layout.test.tsx Children rendering, Inter font className, lang attribute, metadata export validation
Data Resource (amplify/data/resource.ts) __tests__/amplify/data/resource.test.ts Schema definition with Todo model, content field, publicApiKey authorization, defineData config with apiKey auth mode
Auth Resource (amplify/auth/resource.ts) __tests__/amplify/auth/resource.test.ts defineAuth invocation, email-based login configuration
Backend Definition (amplify/backend.ts) __tests__/amplify/backend.test.ts defineBackend called with correct auth and data resources

Additional Files

  • Dockerfile and .dockerignore for containerized test execution
  • npm test and npm run test:coverage scripts added to package.json
  • Testing devDependencies added: jest, ts-jest, jest-environment-jsdom, @testing-library/react, @testing-library/jest-dom, @types/jest

Notes

  • This does not modify any existing application or Amplify backend source code
  • This does not include integration tests or end-to-end tests; scope is limited to unit tests
  • AWS Amplify modules (generateClient, defineAuth, defineData, defineBackend) are fully mocked to isolate unit test behavior from cloud services
  • package-lock.json is not updated in this PR; dependencies should be installed via npm install after merge
  • The Dockerfile references base-custom-mcp-image:latest as a base image for containerized test runs

- Set up Jest with ts-jest, jsdom environment, and Testing Library
- Add unit tests for App component (rendering, observeQuery, createTodo, UI)
- Add unit tests for RootLayout component (children rendering, metadata)
- Add unit tests for Amplify data resource (schema, Todo model, auth rules)
- Add unit tests for Amplify auth resource (defineAuth, email login config)
- Add unit tests for backend definition (defineBackend with auth and data)
- Add mocks for CSS/static files and AWS Amplify modules
- Add Dockerfile and .dockerignore for containerized test execution
- Add test and test:coverage npm scripts to package.json
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