Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
charmingduchess committed Oct 24, 2023
1 parent 8459034 commit 88cf912
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/components/SearchForm/SearchForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ describe("SearchForm", () => {
screen.getByRole("button", { name: "Search" }),
new MouseEvent("click")
)
beforeEach(() => {
mockRouter.query.q = ""
})
afterEach(async () => {
const input = screen.getByRole("textbox")
await userEvent.clear(input)
Expand All @@ -35,7 +38,7 @@ describe("SearchForm", () => {
await userEvent.selectOptions(searchScopeSelect, "journal_title")
submit()
expect(mockRouter.asPath).toBe(
"/search?q=spaghettispaghetti&search_scope=journal_title"
"/search?q=spaghetti&search_scope=journal_title"
)
})
})
Expand Down
4 changes: 3 additions & 1 deletion src/components/SearchForm/SearchForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import { BASE_URL, PATHS } from "../../config/constants"
*/
const SearchForm = () => {
const router = useRouter()
const [searchTerm, setSearchTerm] = useState((router.query.q as string) || "")
const [searchTerm, setSearchTerm] = useState(
(router?.query?.q as string) || ""
)
const [searchScope, setSearchScope] = useState("all")

const handleSubmit = async (e: SyntheticEvent) => {
Expand Down

0 comments on commit 88cf912

Please sign in to comment.