Skip to content

Conversation

@codomposer
Copy link
Contributor

Add unit testing infrastructure for components

Description

This PR adds comprehensive unit testing infrastructure to the CoreUI React Admin Template using Vitest and React Testing Library. The template previously had no testing setup, which made it difficult to ensure code quality and prevent regressions.

Changes

Testing Infrastructure

  • Vitest Configuration (vitest.config.mjs) - Configured Vitest with JSX support for .js files
  • Test Setup (src/setupTests.js) - Added mocks for window.matchMedia and window.getComputedStyle
  • Package Dependencies - Added testing libraries:
    • vitest - Fast unit test framework optimized for Vite
    • @testing-library/react - React component testing utilities
    • @testing-library/jest-dom - Custom jest matchers for DOM assertions
    • @vitest/ui - Interactive test UI
    • jsdom - DOM implementation for Node.js

Test Files Created (8 files, 37 tests total)

  • ✅ src/App.test.js (3 tests)
  • ✅ src/store.test.js (7 tests)
  • ✅ src/components/AppFooter.test.js (6 tests)
  • ✅ src/components/AppHeader.test.js (6 tests)
  • ✅ src/components/AppSidebar.test.js (5 tests)
  • ✅ src/components/AppSidebarNav.test.js (5 tests)
  • ✅ src/components/AppBreadcrumb.test.js (2 tests)
  • ✅ src/components/AppContent.test.js (3 tests)

Documentation

  • README.md - Added comprehensive Testing section with:
    • Running tests commands
    • Test structure explanation
    • Code examples for writing tests
    • Current test coverage list

NPM Scripts Added

"test": "vitest",
"test:ui": "vitest --ui",
"test:coverage": "vitest --coverage"

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