Skip to content

Commit 9f1beb0

Browse files
committed
test(useRecentSearches): ignore blank input
1 parent 0e9b7a6 commit 9f1beb0

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

hooks/useRecentSearches.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,35 @@ describe('useRecentSearches', () => {
3434
});
3535
expect(result.current.searches[0]).toBe('torvalds');
3636
});
37+
it('ignores empty string input', () => {
38+
const { result } = renderHook(() => useRecentSearches());
39+
40+
act(() => {
41+
result.current.addSearch('');
42+
});
43+
44+
expect(result.current.searches).toEqual([]);
45+
});
46+
47+
it('ignores whitespace-only input', () => {
48+
const { result } = renderHook(() => useRecentSearches());
49+
50+
act(() => {
51+
result.current.addSearch(' ');
52+
});
53+
54+
expect(result.current.searches).toEqual([]);
55+
});
56+
57+
it('ignores newline-only input', () => {
58+
const { result } = renderHook(() => useRecentSearches());
59+
60+
act(() => {
61+
result.current.addSearch('\n');
62+
});
63+
64+
expect(result.current.searches).toEqual([]);
65+
});
3766

3867
it('deduplicates — moves existing to front', () => {
3968
const { result } = renderHook(() => useRecentSearches());

0 commit comments

Comments
 (0)