@directus/api
Version:
Directus is a real-time API and App dashboard for managing SQL database content
52 lines (51 loc) • 1.82 kB
TypeScript
/**
* Cache mocking utilities for service tests
* Provides simplified mocks for src/cache module used in service testing
*/
/**
* Creates a standard cache mock for service tests
* Returns mock functions for vi.mock() and spies for testing cache behavior
*
* @returns Object with mock functions at root level and spies nested under 'spies' property
*
* @example
* ```typescript
* // Standard usage for vi.mock()
* vi.mock('../cache.js', async () => {
* const { mockCache } = await import('../test-utils/cache.js');
* return mockCache();
* });
*
* // Testing cache clearing with spies
* import { getCache } from '../cache.js';
* import { mockCache } from '../test-utils/cache.js';
*
* test('should clear cache after update', async () => {
* const { spies } = mockCache();
* vi.mocked(getCache).mockReturnValue(spies.mockCacheReturn as any);
*
* const service = new YourService({ knex: db, schema });
* await service.updateOne('1', { name: 'Updated' });
*
* expect(spies.clearSpy).toHaveBeenCalled();
* });
* ```
*/
export declare function mockCache(): {
getCache: import("vitest").Mock<(...args: any[]) => any>;
getCacheValue: import("vitest").Mock<(...args: any[]) => any>;
setCacheValue: import("vitest").Mock<(...args: any[]) => any>;
clearSystemCache: import("vitest").Mock<(...args: any[]) => any>;
spies: {
clearSpy: import("vitest").Mock<(...args: any[]) => any>;
systemClearSpy: import("vitest").Mock<(...args: any[]) => any>;
getCacheSpy: import("vitest").Mock<(...args: any[]) => any>;
setCacheSpy: import("vitest").Mock<(...args: any[]) => any>;
mockCacheReturn: {
cache: any;
systemCache: any;
localSchemaCache: any;
lockCache: undefined;
};
};
};