mirror of
https://github.com/barthuijgen/factorio-sites.git
synced 2025-01-05 13:20:27 +02:00
Fix unit tests
This commit is contained in:
parent
8da43e3a19
commit
7e31990201
@ -1,9 +1,11 @@
|
||||
import React from "react";
|
||||
import { render } from "@testing-library/react";
|
||||
import { act, render } from "@testing-library/react";
|
||||
import Index from "../src/pages/index";
|
||||
import * as nextRouter from "next/router";
|
||||
|
||||
const useRouter = jest.spyOn(nextRouter, "useRouter");
|
||||
(global as any).fetch = jest.fn(() => Promise.resolve());
|
||||
console.error = jest.fn();
|
||||
|
||||
describe("Index", () => {
|
||||
it("should render successfully", () => {
|
||||
|
@ -60,8 +60,12 @@ export const useFbeData = (): FactorioData | null => {
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
const result = await fetch("/api/fbe-proxy/data.json").then((res) => res.json());
|
||||
setData(result);
|
||||
const result = await fetch("/api/fbe-proxy/data.json")
|
||||
.then((res) => res.json())
|
||||
.catch(() => {
|
||||
console.error("Failed to fetch data.json");
|
||||
});
|
||||
if (result) setData(result);
|
||||
})();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
@ -6,7 +6,7 @@ export const useRouterQueryToHref = () => {
|
||||
const router = useRouter();
|
||||
return useCallback(
|
||||
(override: Record<string, string | string[] | null>, overrideAll = false) => {
|
||||
const query = overrideAll ? override : { ...router.query, ...override };
|
||||
const query = overrideAll ? override : { ...router?.query, ...override };
|
||||
return stringifyQuery(query);
|
||||
},
|
||||
[router]
|
||||
|
@ -83,7 +83,7 @@ export const Index: NextPage<IndexProps> = ({
|
||||
|
||||
useEffect(() => {
|
||||
setSearchQuery((router.query.q as string) || "");
|
||||
}, [router.query.q]);
|
||||
}, [router?.query.q]);
|
||||
|
||||
if (!data) return null;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user