import * as React from 'react'; import { MemoryRouter } from 'react-router'; import { cleanup, fireEvent, render } from '@testing-library/react'; import { act, renderHook } from '@testing-library/react-hooks'; import useRouter, { Context } from './useRouter'; describe('hook useRouter', () => { afterEach(cleanup); const Example: React.FunctionComponent = ({ children }) => ({children}); const HookOmmit = ({ test }: { test?: (context: Context) => void }) => { const result = useRouter(); test && test(result); return (); }; test('should return location, history and match', () => { const { container } = render( { expect(match).toBeDefined(); expect(history).toBeDefined(); expect(location).toBeDefined(); }} /> ); }); test('should return location, history and match', (finish) => { const { container } = render( ); const button = container.children[0]; expect(button.textContent).toBe('/'); fireEvent.click(button); setTimeout(() => { expect(button.textContent).toBe('/test'); finish(); }, 0); }); });