syntropylog
Version:
An instance manager with observability for Node.js applications
60 lines • 1.7 kB
JavaScript
import { createSyntropyLogMock, resetSyntropyLogMocks, } from './SyntropyLogMock';
/**
* Create a test helper for SyntropyLog testing
*
* @param spyFn - Optional spy function for framework compatibility (vi.fn, jest.fn, etc.)
*
* @example
* ```typescript
* // For Vitest
* const testHelper = createTestHelper(vi.fn);
*
* // For Jest
* const testHelper = createTestHelper(jest.fn);
*
* // For Jasmine
* const testHelper = createTestHelper(jasmine.createSpy);
*
* // Without spy (basic functionality only)
* const testHelper = createTestHelper();
*
* describe('MyService', () => {
* beforeEach(() => testHelper.beforeEach());
* afterEach(() => testHelper.afterEach());
*
* it('should work', () => {
* const service = new MyService(testHelper.mockSyntropyLog);
* // ... test logic
* });
* });
* ```
*/
export function createTestHelper(spyFn) {
const mockSyntropyLog = createSyntropyLogMock(spyFn);
return {
mockSyntropyLog,
beforeEach: () => {
resetSyntropyLogMocks();
},
afterEach: () => {
// Clean up if needed
},
};
}
/**
* Create a service with SyntropyLog mock for testing
*
* @param ServiceClass - The service class to instantiate
* @param mockSyntropyLog - The mock SyntropyLog instance
* @returns Instance of the service with mock injected
*
* @example
* ```typescript
* const mockSyntropyLog = createSyntropyLogMock();
* const userService = createServiceWithMock(UserService, mockSyntropyLog);
* ```
*/
export function createServiceWithMock(ServiceClass, mockSyntropyLog) {
return new ServiceClass(mockSyntropyLog);
}
//# sourceMappingURL=test-helper.js.map