withRouteAnalytics.spec.tsx 980 B

12345678910111213141516171819202122232425262728293031323334
  1. import {useEffect} from 'react';
  2. import {render} from 'sentry-test/reactTestingLibrary';
  3. import {RouteAnalyticsContext} from 'sentry/views/routeAnalyticsContextProvider';
  4. import withRouteAnalytics from './withRouteAnalytics';
  5. function TestComponent({setRouteAnalyticsParams}) {
  6. useEffect(() => {
  7. setRouteAnalyticsParams({foo: 'bar'});
  8. }, [setRouteAnalyticsParams]);
  9. return <div>hi</div>;
  10. }
  11. const WrappedComponent = withRouteAnalytics(TestComponent);
  12. describe('withRouteAnalytics', function () {
  13. it('passes context to children as props', function () {
  14. const setRouteAnalyticsParams = jest.fn();
  15. render(
  16. <RouteAnalyticsContext.Provider
  17. value={{
  18. setRouteAnalyticsParams,
  19. setDisableRouteAnalytics: jest.fn(),
  20. setOrganization: jest.fn(),
  21. }}
  22. >
  23. <WrappedComponent />
  24. </RouteAnalyticsContext.Provider>
  25. );
  26. expect(setRouteAnalyticsParams).toHaveBeenCalledWith({foo: 'bar'});
  27. });
  28. });