UNPKG

@vergiss/chooks

Version:
26 lines 838 B
import "core-js/modules/es.object.define-property"; import { act, renderHook } from '@testing-library/react-hooks'; import { useUrlParams } from '../index'; describe('useUrlParams', function () { it('should be defined', function () { expect(useUrlParams).toBeDefined(); }); it('should return params value', function () { Object.defineProperty(window, "location", { value: { href: 'https://localhost' }, writable: true }); window.location.href = 'https://www.example.com?hello=world'; var hook = renderHook(function () { return useUrlParams('hello'); }); expect(hook.result.current).toBe('world'); act(function () { window.location.href = 'https://www.example.com?hello=coma'; hook.rerender(); }); expect(hook.result.current).toBe('coma'); }); });