useLocation.spec.tsx 1010 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import {createMemoryHistory, Route, Router, RouterContext} from 'react-router';
  2. import {render} from 'sentry-test/reactTestingLibrary';
  3. import {useLocation} from 'sentry/utils/useLocation';
  4. import {RouteContext} from 'sentry/views/routeContext';
  5. describe('useLocation', () => {
  6. it('returns the current location object', function () {
  7. let location;
  8. function HomePage() {
  9. location = useLocation();
  10. return null;
  11. }
  12. const memoryHistory = createMemoryHistory();
  13. memoryHistory.push('/?hello');
  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(location.pathname).toBe('/');
  29. expect(location.query).toEqual({hello: null});
  30. expect(location.search).toBe('?hello');
  31. });
  32. });