Skip to content

Commit

Permalink
fix a couple tests broken by moving to std. error boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
pvh committed Jan 6, 2025
1 parent 0f787e3 commit 95f4882
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions packages/automerge-repo-react-hooks/test/useDocument.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ describe("useDocument", () => {
React.act(() => handleA.delete())

// Should trigger error boundary
await waitFor(() => {
expect(onError).toHaveBeenCalledWith(expect.any(Error))
})
expect(screen.getByTestId("error")).toHaveTextContent("Error")
})

it("should switch documents when url changes", async () => {
Expand Down Expand Up @@ -169,32 +167,23 @@ describe("useDocument", () => {
expect(onDoc).toHaveBeenCalledWith({ foo: "B" })
})

// Test unavailable document
it("should handle unavailable documents", async () => {
const { wrapper, repo } = setup()
const onError = vi.fn()

// Create handle for nonexistent document
const url = generateAutomergeUrl()

render(
<ErrorBoundary
fallback={<div data-testid="error">Error</div>}
onError={onError}
>
<ErrorBoundary fallback={<div data-testid="error">Error</div>}>
<Suspense fallback={<div data-testid="loading">Loading...</div>}>
<Component url={url} onDoc={vi.fn()} />
</Suspense>
</ErrorBoundary>,
{ wrapper }
)

await waitFor(() => {
expect(onError).toHaveBeenCalledWith(
expect.objectContaining({
message: expect.stringContaining("unavailable"),
})
)
waitFor(() => {
expect(screen.getByTestId("error")).toHaveTextContent("Error")
})
})

Expand Down

0 comments on commit 95f4882

Please sign in to comment.