Files
2024-02-15 17:01:50 +00:00

37 lines
1.0 KiB
TypeScript

import {useEffect} from 'react';
import {render} from 'sentry-test/reactTestingLibrary';
import {RouteAnalyticsContext} from 'sentry/views/routeAnalyticsContextProvider';
import withRouteAnalytics from './withRouteAnalytics';
function TestComponent({setRouteAnalyticsParams}) {
useEffect(() => {
setRouteAnalyticsParams({foo: 'bar'});
}, [setRouteAnalyticsParams]);
return <div>hi</div>;
}
const WrappedComponent = withRouteAnalytics(TestComponent);
describe('withRouteAnalytics', function () {
it('passes context to children as props', function () {
const setRouteAnalyticsParams = jest.fn();
render(
<RouteAnalyticsContext.Provider
value={{
setRouteAnalyticsParams,
setDisableRouteAnalytics: jest.fn(),
setOrganization: jest.fn(),
setEventNames: jest.fn(),
previousUrl: '',
}}
>
<WrappedComponent />
</RouteAnalyticsContext.Provider>
);
expect(setRouteAnalyticsParams).toHaveBeenCalledWith({foo: 'bar'});
});
});