useNavigate.spec.tsx 908 B

123456789101112131415161718192021222324252627282930313233343536
  1. import {createMemoryHistory, Route, Router, RouterContext} from 'react-router';
  2. import {render} from 'sentry-test/reactTestingLibrary';
  3. import {useNavigate} from 'sentry/utils/useNavigate';
  4. import {RouteContext} from 'sentry/views/routeContext';
  5. describe('useNavigate', () => {
  6. it('returns the navigate function', function () {
  7. let navigate;
  8. function HomePage() {
  9. navigate = useNavigate();
  10. return null;
  11. }
  12. const memoryHistory = createMemoryHistory();
  13. memoryHistory.push('/');
  14. render(
  15. <Router
  16. history={memoryHistory}
  17. render={props => {
  18. return (
  19. <RouteContext.Provider value={props}>
  20. <RouterContext {...props} />
  21. </RouteContext.Provider>
  22. );
  23. }}
  24. >
  25. <Route path="/" component={HomePage} />
  26. </Router>
  27. );
  28. expect(typeof navigate).toBe('function');
  29. });
  30. });