@plyaz/testing
v1.5.5
Published
Comprehensive testing utilities for the Plyaz ecosystem with enhanced Vitest utilities, React testing helpers, mocks, and assertions
Keywords
Readme
@plyaz/testing
Comprehensive testing utilities for the Plyaz ecosystem
The @plyaz/testing package provides a unified set of testing patterns, mocks, and utilities designed to streamline test writing across React, Next.js, Node.js, and NestJS applications within the Plyaz ecosystem.
🎯 Key Features
- Unified Testing API: Consistent testing patterns across all frameworks
- Enhanced Vitest Utilities: Advanced spy management, module mocking, and lifecycle control
- React Testing Made Easy: Hook testing, component utilities, and provider testing
- Comprehensive Mocks: HTTP, Node.js, React, and framework-specific mocks
- Async Testing: Promise control, timing utilities, and retry mechanisms
- Performance Testing: Benchmarking and performance measurement tools
� Quick Start
import {
// Core utilities
expectObject, expectArray, expectPromise,
spies, mockData, modules
} from '@plyaz/testing';
// Basic test setup
describe('UserService', () => {
const mockRepo = spies.create(repository, 'findUser');
it('should find user by id', async () => {
mockRepo.mockResolvedValue(mockUser);
const result = await userService.findUser('123');
expectObject.toHaveShape(result, { id: 'string', name: 'string' });
});
});📦 Core Modules
Vitest Utilities
Enhanced Vitest utilities with spy management and module mocking:
import { spies, modules, mockData } from '@plyaz/testing';
const spy = spies.create(service, 'getData');
const { unmock } = modules.mock('./config', () => ({ apiUrl: 'test' }));React Testing
Comprehensive React testing with hooks and components:
import { expectHookValue, testLoadingStates } from '@plyaz/testing';
const { result } = renderHook(() => useCounter(5));
expectHookValue(result, 'count', 5);Assertions
Enhanced assertions for complex types and behaviors:
import { expectObject, expectArray, expectPromise } from '@plyaz/testing';
expectObject.toHaveShape(user, { id: 'string', name: 'string' });
expectArray.toContainMatching(users, user => user.isActive);
await expectPromise.toResolveWith(fetchUser('123'), mockUser);Mocks & Factories
Comprehensive mock creation and management:
import { NodeMocks, HttpMocks, ReactMocks } from '@plyaz/testing';
const fs = NodeMocks.createMockFS({ '/test.txt': 'content' });
const req = HttpMocks.createMockHttpRequest({ method: 'POST' });🏗️ Framework Support
- React: Hook testing, component utilities, provider testing
- Next.js: Pages, API routes, SSR/SSG testing, App Router support
- Node.js: File system, process, streams, and crypto mocking
- NestJS: Controllers, services, modules, and dependency injection testing
📚 Documentation
For comprehensive documentation and examples,
Documentation for @plyaz/testing Package API References & Type Definitions - @plyaz/testing [Testing Package
](https://plyaz.atlassian.net/wiki/spaces/SD/pages/43745282/Testing+Package) visit our Testing Package Documentation or the general Confluence Documentation.
Quick links:
- API Reference: Complete function documentation
- Testing Patterns: Best practices and common patterns
- Framework Guides: Specific guides for React, Next.js, Node.js, and NestJS
- Examples: Real-world testing examples
🧰 Integration
This package integrates seamlessly with:
- ✅ TypeScript (strict mode)
- ✅ Vitest testing framework
- ✅ React Testing Library
- ✅ ESLint & Prettier via
@plyaz/devtools - ✅ All Plyaz ecosystem packages
🔧 Installation
npm install --save-dev @plyaz/testing
# or
pnpm add -D @plyaz/testing🧠 Ownership
This package is maintained by the Plyaz engineering team. It provides the foundation for testing across all Plyaz applications and services.
