-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
944c297
commit 76ca89b
Showing
2 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { logger } from "airbrake"; | ||
import ErrorFallback from "components/Error/ErrorFallback"; | ||
import React from "react"; | ||
import { ErrorBoundary } from "react-error-boundary"; | ||
import { setup } from "testUtils"; | ||
import { vi } from "vitest"; | ||
import { axe } from "vitest-axe"; | ||
|
||
import { GraphError } from "./GraphError"; | ||
|
||
vi.mock("airbrake", () => ({ | ||
logger: { | ||
notify: vi.fn(), | ||
}, | ||
})); | ||
|
||
const ThrowError: React.FC = () => { | ||
throw new Error("Something broke"); | ||
}; | ||
|
||
const ThrowGraphError: React.FC = () => { | ||
throw new GraphError("nodeMustFollowFindProperty"); | ||
}; | ||
|
||
it("does not render if a child does not throw an error", () => { | ||
const { queryByRole } = setup( | ||
<ErrorBoundary FallbackComponent={ErrorFallback}> | ||
<h1>No error</h1> | ||
</ErrorBoundary>, | ||
); | ||
expect( | ||
queryByRole("heading", { name: /Invalid graph/ }), | ||
).not.toBeInTheDocument(); | ||
}); | ||
|
||
it("does not render if a child throws a non-Graph error", () => { | ||
const { queryByRole, getByText } = setup( | ||
<ErrorBoundary FallbackComponent={ErrorFallback}> | ||
<ThrowError /> | ||
</ErrorBoundary>, | ||
); | ||
// ErrorFallback displays... | ||
expect(getByText(/Something went wrong/)).toBeInTheDocument(); | ||
// ...but does not show a GraphError | ||
expect( | ||
queryByRole("heading", { name: /Invalid graph/ }), | ||
).not.toBeInTheDocument(); | ||
}); | ||
|
||
it("renders if a child throws an error", () => { | ||
const { queryByText, getByRole } = setup( | ||
<ErrorBoundary FallbackComponent={ErrorFallback}> | ||
<ThrowGraphError /> | ||
</ErrorBoundary>, | ||
); | ||
|
||
expect(queryByText(/Something went wrong/)).not.toBeInTheDocument(); | ||
expect(getByRole("heading", { name: /Invalid graph/ })).toBeInTheDocument(); | ||
}); | ||
|
||
it("does not call Airbrake", () => { | ||
const loggerSpy = vi.spyOn(logger, "notify"); | ||
|
||
setup( | ||
<ErrorBoundary FallbackComponent={ErrorFallback}> | ||
<ThrowGraphError /> | ||
</ErrorBoundary>, | ||
); | ||
|
||
expect(loggerSpy).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("should not have accessability violations", async () => { | ||
const { container } = setup( | ||
<ErrorBoundary FallbackComponent={ErrorFallback}> | ||
<ThrowGraphError /> | ||
</ErrorBoundary>, | ||
); | ||
const results = await axe(container); | ||
expect(results).toHaveNoViolations(); | ||
}); |