routeError.spec.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import * as Sentry from '@sentry/react';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, waitFor} from 'sentry-test/reactTestingLibrary';
  4. import {RouteError} from 'sentry/views/routeError';
  5. describe('RouteError', function () {
  6. const {router, routerContext, organization} = initializeOrg({
  7. ...initializeOrg(),
  8. router: TestStubs.router({
  9. routes: [
  10. {path: '/'},
  11. {path: '/:orgId/'},
  12. {name: 'this should be skipped'},
  13. {path: '/organizations/:orgId/'},
  14. {path: 'api-keys/', name: 'API Key'},
  15. ],
  16. }),
  17. });
  18. const {location, params, routes} = router;
  19. it('captures errors with sentry', async function () {
  20. render(
  21. <RouteError
  22. router={router}
  23. routes={routes}
  24. error={new Error('Big Bad Error')}
  25. location={location}
  26. params={params}
  27. organization={organization}
  28. />,
  29. {
  30. context: routerContext,
  31. }
  32. );
  33. await waitFor(() =>
  34. expect(Sentry.captureException).toHaveBeenCalledWith(
  35. expect.objectContaining({
  36. message: 'Big Bad Error: /organizations/:orgId/api-keys/',
  37. })
  38. )
  39. );
  40. expect(Sentry.showReportDialog).toHaveBeenCalled();
  41. });
  42. });