Skip to content

Add unit testing framework with Jest and React Testing Library#5

Open
bigweavergammainternal[bot] wants to merge 1 commit intomainfrom
dev-branch-20260127-052821
Open

Add unit testing framework with Jest and React Testing Library#5
bigweavergammainternal[bot] wants to merge 1 commit intomainfrom
dev-branch-20260127-052821

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


This pull request was generated by @kiro-agent 👻

You can interact with this PR using the following commands:

  • /kiro fix - Apply fixes for specific feedback
  • /kiro all - Apply all recommended changes

Learn more about Kiro automation

Summary

This PR establishes a comprehensive unit testing framework for the amplify-next-template repository using Jest and React Testing Library, specifically configured for Next.js 14 applications. The implementation provides a solid foundation for maintaining code quality and ensuring component reliability through automated testing.

Configuration Files Added:

  • jest.config.js - Jest configuration using Next.js's built-in Jest support

    • Configured test environment as jsdom for React component testing
    • Module path alias mapping for @/ imports
    • Exclusion patterns for node_modules, .next, and amplify directories
    • Coverage collection settings for app directory
  • jest.setup.js - Jest setup file with essential mocks

    • Integration with @testing-library/jest-dom for extended matchers
    • Mock for next/font/google (Inter font)
    • Mock for aws-amplify configuration
    • Mock for aws-amplify/data with generateClient functionality
    • Mock for @aws-amplify/ui-react/styles.css
    • Mock for amplify_outputs.json configuration
    • Mock for window.prompt browser API

Test Files Added:

  • __tests__/page.test.tsx - Tests for the main page component (app/page.tsx)

    • Rendering tests: heading, button, success message, tutorial link, empty todo list
    • Todo list subscription tests: mount subscription, data display, key rendering
    • Create todo functionality tests: prompt interaction, create with content, cancel handling
    • Accessibility tests: main landmark, heading hierarchy
  • __tests__/layout.test.tsx - Tests for the root layout component (app/layout.tsx)

    • Rendering tests: children rendering, html lang attribute, body with font class
    • Multiple children handling tests
    • Metadata export tests: title, description validation
    • Accessibility tests: document structure, language attribute

Test Scripts Added:

  • test - Run all tests: jest
  • test:watch - Run tests in watch mode: jest --watch
  • test:coverage - Run tests with coverage report: jest --coverage

Dependencies Added:

  • jest@^29.7.0 - JavaScript testing framework
  • jest-environment-jsdom@^29.7.0 - JSDOM environment for browser-like testing
  • ts-jest@^29.2.5 - TypeScript preprocessor for Jest
  • @testing-library/react@^16.0.1 - React component testing utilities
  • @testing-library/jest-dom@^6.5.0 - Custom Jest matchers for DOM assertions
  • @types/jest@^29.5.13 - TypeScript definitions for Jest

######[This description was generated by Claude]

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