diff --git a/applicationinsights-react-js/test/AppInsightsErrorBoundary.test.tsx b/applicationinsights-react-js/test/AppInsightsErrorBoundary.test.tsx index e55a225..562ff86 100644 --- a/applicationinsights-react-js/test/AppInsightsErrorBoundary.test.tsx +++ b/applicationinsights-react-js/test/AppInsightsErrorBoundary.test.tsx @@ -95,19 +95,24 @@ describe("", () => { function NewError() { const navigate = useNavigate(); - const ErrorDisplay = () =>
You are on the error page
; + function handleClick() { navigate(-1); } + return (
- - - -
+
You are on the error page
+ + ); + } + + function BackButton() { + const navigate = useNavigate(); + + return ( + ); } @@ -116,48 +121,38 @@ describe("", () => { if (orgError) { console.error = msg => { /* Do Nothing */ }; } - const Home = () =>
Home Page
- const About = () =>
About Page
+ const Home = () =>
Home Page
; + const About = () => { + throw new Error("something went wrong"); + }; try { render( +
- Home - About - Error - - - } /> - } /> - } /> - - -
+ Home + About + + + } /> + } /> + + + +
); expect(screen.getByText(/Home Page/i)).toBeInTheDocument() - - // go to error page - await userEvent.click(screen.getByText(/error/i)) - expect(screen.getByText(/You are on the error page/i)).toBeInTheDocument() - expect(trackExceptionSpy).toHaveBeenCalledTimes(1); - // go back to home page - await userEvent.click(screen.getByText(/go back/i)); - expect(screen.getByText(/Home Page/i)).toBeInTheDocument(); - expect(trackExceptionSpy).toHaveBeenCalledTimes(1); - - // go to error page again - await userEvent.click(screen.getByText(/error/i)) - expect(screen.getByText(/You are on the error page/i)).toBeInTheDocument() - console.log("track time", trackExceptionSpy.mock.calls.length); - - // navigate to about page - await userEvent.click(screen.getByText(/about/i)) - expect(screen.getByText(/About Page/i)).toBeInTheDocument() + // navigate to about page (throws error, so show error component) + await userEvent.click(screen.getByText(/about/i)); + expect(screen.getByText(/You are on the error page/i)).toBeInTheDocument(); console.log("track time", trackExceptionSpy.mock.calls.length); + // go back to home page (no error, so show home component) + await userEvent.click(screen.getByText(/go back/i)); + expect(screen.getByText(/Home Page/i)).toBeInTheDocument(); } finally { if (orgError) { console.error = orgError;