1
0
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:
Bart 2021-03-22 21:58:23 +01:00
parent 8da43e3a19
commit 7e31990201
4 changed files with 11 additions and 5 deletions

View File

@ -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", () => {

View File

@ -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
}, []);

View File

@ -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]

View File

@ -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;