pageError.spec.jsx 922 B

123456789101112131415161718192021222324252627282930313233343536
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import {
  3. PageErrorAlert,
  4. PageErrorProvider,
  5. usePageError,
  6. } from 'sentry/utils/performance/contexts/pageError';
  7. function SimpleErrorButton() {
  8. const context = usePageError();
  9. return (
  10. <button
  11. data-test-id="pageErrorButton"
  12. onClick={() => context.setPageError('Fresh new error')}
  13. />
  14. );
  15. }
  16. describe('Performance > Contexts > pageError', function () {
  17. it('Check that pageError context will render error alert', async function () {
  18. render(
  19. <PageErrorProvider>
  20. <div data-test-id="errorAlert">
  21. <PageErrorAlert />
  22. </div>
  23. <SimpleErrorButton />
  24. </PageErrorProvider>
  25. );
  26. const button = await screen.findByTestId('pageErrorButton');
  27. userEvent.click(button);
  28. expect(await screen.findByTestId('errorAlert')).toHaveTextContent('Fresh new error');
  29. });
  30. });