diff --git a/hooks/useRecentSearches.type-compiler.test.ts b/hooks/useRecentSearches.type-compiler.test.ts new file mode 100644 index 000000000..da9ab55c3 --- /dev/null +++ b/hooks/useRecentSearches.type-compiler.test.ts @@ -0,0 +1,55 @@ +import { describe, it, expect, expectTypeOf } from 'vitest'; +import { useRecentSearches, STORAGE_KEY, MAX_SEARCHES } from './useRecentSearches'; + +// Infer the hook's public API directly from its implementation. +type UseRecentSearchesReturn = ReturnType; + +describe('useRecentSearches — TypeScript compiler validation & schema constraints', () => { + it('1. exposes STORAGE_KEY and MAX_SEARCHES with correct primitive types', () => { + expectTypeOf(STORAGE_KEY).toBeString(); + expectTypeOf(MAX_SEARCHES).toBeNumber(); + + expect(typeof STORAGE_KEY).toBe('string'); + expect(typeof MAX_SEARCHES).toBe('number'); + }); + + it('2. useRecentSearches accepts no arguments', () => { + expectTypeOf(useRecentSearches).parameters.toEqualTypeOf<[]>(); + + expect(useRecentSearches.length).toBe(0); + }); + + it('3. returns the expected public API shape', () => { + expectTypeOf().toEqualTypeOf<{ + searches: string[]; + addSearch: (query: string) => void; + clearSearches: () => void; + removeSearch: (query: string) => void; + }>(); + + expectTypeOf().toEqualTypeOf(); + }); + + it('4. enforces function parameter and return types', () => { + expectTypeOf().parameters.toEqualTypeOf<[string]>(); + expectTypeOf().returns.toBeVoid(); + + expectTypeOf().parameters.toEqualTypeOf<[string]>(); + expectTypeOf().returns.toBeVoid(); + + expectTypeOf().parameters.toEqualTypeOf<[]>(); + expectTypeOf().returns.toBeVoid(); + }); + + it('5. verifies required fields and inferred property types', () => { + expectTypeOf().toHaveProperty('searches'); + expectTypeOf().toHaveProperty('addSearch'); + expectTypeOf().toHaveProperty('removeSearch'); + expectTypeOf().toHaveProperty('clearSearches'); + + expectTypeOf().items.toEqualTypeOf(); + + expect(STORAGE_KEY.length).toBeGreaterThan(0); + expect(MAX_SEARCHES).toBeGreaterThan(0); + }); +});