44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import { render, waitFor } from "@testing-library/react";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
|
|
vi.mock("@sentry/react-router", () => {
|
|
const sentryOnError = vi.fn();
|
|
return {
|
|
__esModule: true,
|
|
sentryOnError,
|
|
};
|
|
});
|
|
|
|
import * as Sentry from "@sentry/react-router";
|
|
|
|
import { RouteTracingProvider, sentryHydrationErrorHandler } from "./routeTracing";
|
|
|
|
const mockedOnError = Sentry.sentryOnError as unknown as ReturnType<typeof vi.fn>;
|
|
|
|
describe("sentryHydrationErrorHandler", () => {
|
|
it("delegates to Sentry.sentryOnError", async () => {
|
|
const err = new Error("hydration-boom");
|
|
const info = { errorInfo: { componentStack: "test-stack" } as React.ErrorInfo };
|
|
sentryHydrationErrorHandler(err, info);
|
|
await waitFor(() => expect(mockedOnError).toHaveBeenCalledWith(err, info));
|
|
});
|
|
|
|
it("swallows exceptions thrown by the SDK", () => {
|
|
mockedOnError.mockImplementationOnce(() => {
|
|
throw new Error("sdk-down");
|
|
});
|
|
expect(() => sentryHydrationErrorHandler(new Error("boom"), {})).not.toThrow();
|
|
});
|
|
});
|
|
|
|
describe("RouteTracingProvider", () => {
|
|
it("renders its children unchanged", () => {
|
|
const { getByText } = render(
|
|
<RouteTracingProvider>
|
|
<span>route-tracing-content</span>
|
|
</RouteTracingProvider>
|
|
);
|
|
expect(getByText("route-tracing-content")).toBeTruthy();
|
|
});
|
|
});
|