Skip to content

Commit

Permalink
test: Add checks for "LOADING" text in authorization tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ktun95 committed Aug 21, 2024
1 parent b6d6663 commit 1b245cc
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/auth/src/__tests__/useAuthorization.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { test, expect, vi } from "vitest"
import { render, screen } from "@testing-library/react"
import { useAuthorization } from "../useAuthorization"
import { render, screen } from "@testing-library/react"
import { useAuthorization } from "../useAuthorization"

const mockUseLogto = vi.hoisted(() => vi.fn())

Expand Down Expand Up @@ -30,8 +32,8 @@ test("A user without a matching role is unauthorized", async () => {
isAuthenticated: true,
})

const { getByText } = render(<TestComponent authorizedRoles={["admin"]} />)
expect(getByText("LOADING")).toBeInTheDocument()
render(<TestComponent authorizedRoles={["admin"]} />)
expect(screen.getByText("LOADING")).toBeInTheDocument()
expect(await screen.findByText("UNAUTHORIZED")).toBeInTheDocument()
})

Expand All @@ -41,7 +43,7 @@ test("A user with a matching role is authorized", async () => {
isAuthenticated: true,
})

const { getByText } = render(<TestComponent authorizedRoles={["admin"]} />)
expect(getByText("LOADING")).toBeInTheDocument()
render(<TestComponent authorizedRoles={["admin"]} />)
expect(screen.getByText("LOADING")).toBeInTheDocument()
expect(await screen.findByText("AUTHORIZED")).toBeInTheDocument()
})

0 comments on commit 1b245cc

Please sign in to comment.