mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-07-29 16:52:00 +08:00

* chore: added jsx-runtime plugin in eslint tsconfig Signed-off-by: GermaVinsmoke <vaibhav1180@gmail.com> * chore: updated react imports Signed-off-by: GermaVinsmoke <vaibhav1180@gmail.com> * chore: renamed redux dispatch Signed-off-by: GermaVinsmoke <vaibhav1180@gmail.com> * fix: build is fixed --------- Signed-off-by: GermaVinsmoke <vaibhav1180@gmail.com> Co-authored-by: Palash Gupta <palashgdev@gmail.com>
57 lines
1.7 KiB
TypeScript
57 lines
1.7 KiB
TypeScript
import { act, renderHook } from '@testing-library/react';
|
|
import { createMemoryHistory } from 'history';
|
|
import { Router } from 'react-router-dom';
|
|
|
|
import useUrlQuery from './useUrlQuery';
|
|
|
|
describe('useUrlQuery', () => {
|
|
test('returns URLSearchParams object for the current URL search', () => {
|
|
const history = createMemoryHistory({
|
|
initialEntries: ['/test?param1=value1¶m2=value2'],
|
|
});
|
|
|
|
const { result } = renderHook(() => useUrlQuery(), {
|
|
wrapper: ({ children }) => <Router history={history}>{children}</Router>,
|
|
});
|
|
|
|
expect(result.current.get('param1')).toBe('value1');
|
|
expect(result.current.get('param2')).toBe('value2');
|
|
});
|
|
|
|
test('updates URLSearchParams object when URL search changes', () => {
|
|
const history = createMemoryHistory({
|
|
initialEntries: ['/test?param1=value1'],
|
|
});
|
|
|
|
const { result, rerender } = renderHook(() => useUrlQuery(), {
|
|
wrapper: ({ children }) => <Router history={history}>{children}</Router>,
|
|
});
|
|
|
|
expect(result.current.get('param1')).toBe('value1');
|
|
expect(result.current.get('param2')).toBe(null);
|
|
|
|
act(() => {
|
|
history.push('/test?param1=newValue1¶m2=value2');
|
|
});
|
|
|
|
rerender();
|
|
|
|
expect(result.current.get('param1')).toBe('newValue1');
|
|
expect(result.current.get('param2')).toBe('value2');
|
|
});
|
|
|
|
test('returns empty URLSearchParams object when no query parameters are present', () => {
|
|
const history = createMemoryHistory({
|
|
initialEntries: ['/test'],
|
|
});
|
|
|
|
const { result } = renderHook(() => useUrlQuery(), {
|
|
wrapper: ({ children }) => <Router history={history}>{children}</Router>,
|
|
});
|
|
|
|
expect(result.current.toString()).toBe('');
|
|
expect(result.current.get('param1')).toBe(null);
|
|
expect(result.current.get('param2')).toBe(null);
|
|
});
|
|
});
|