useRouteAnalyticsHookSetup.spec.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render} from 'sentry-test/reactTestingLibrary';
  3. import HookStore from 'sentry/stores/hookStore';
  4. import {OrganizationContext} from 'sentry/views/organizationContext';
  5. import {RouteAnalyticsContext} from 'sentry/views/routeAnalyticsContextProvider';
  6. import useRouteAnalyticsHookSetup from './useRouteAnalyticsHookSetup';
  7. function TestComponent() {
  8. useRouteAnalyticsHookSetup();
  9. return <div>hi</div>;
  10. }
  11. describe('useRouteAnalyticsHookSetup', function () {
  12. it('registers callback', function () {
  13. const {organization} = initializeOrg();
  14. const setOrganization = jest.fn();
  15. render(
  16. <RouteAnalyticsContext.Provider
  17. value={{
  18. setOrganization,
  19. setDisableRouteAnalytics: jest.fn(),
  20. setRouteAnalyticsParams: jest.fn(),
  21. }}
  22. >
  23. <OrganizationContext.Provider value={organization}>
  24. <TestComponent />
  25. </OrganizationContext.Provider>
  26. </RouteAnalyticsContext.Provider>
  27. );
  28. expect(
  29. HookStore.getCallback('react-hook:route-activated', 'setOrganization')
  30. ).toEqual(setOrganization);
  31. });
  32. });