Comprehensive testing utilities for the Plyaz ecosystem with enhanced Vitest utilities, React testing helpers, mocks, and assertions
npm install @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.
- 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
``typescript
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' });
});
});
`
typescript
import { spies, modules, mockData } from '@plyaz/testing';const spy = spies.create(service, 'getData');
const { unmock } = modules.mock('./config', () => ({ apiUrl: 'test' }));
`$3
Comprehensive React testing with hooks and components:
`typescript
import { expectHookValue, testLoadingStates } from '@plyaz/testing';const { result } = renderHook(() => useCounter(5));
expectHookValue(result, 'count', 5);
`$3
Enhanced assertions for complex types and behaviors:
`typescript
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);
`$3
Comprehensive mock creation and management:
`typescript
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
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
`bash
npm install --save-dev @plyaz/testing
or
pnpm add -D @plyaz/testing
``This package is maintained by the Plyaz engineering team. It provides the foundation for testing across all Plyaz applications and services.