diff --git a/app/+not-found.tsx b/app/+not-found.tsx new file mode 100644 index 0000000..5f59570 --- /dev/null +++ b/app/+not-found.tsx @@ -0,0 +1,21 @@ +import { Button } from "@/components/ui/button"; +import { Screen } from "@/components/ui/screen"; +import { Text } from "@/components/ui/text"; +import { useRouter } from "expo-router"; +import { View } from "react-native"; + +export default function NotFoundScreen() { + const router = useRouter(); + + return ( + + + Page not found + The page you're looking for doesn't exist. + + + + ); +} diff --git a/app/_layout.tsx b/app/_layout.tsx index 0fbea76..8ce9be0 100644 --- a/app/_layout.tsx +++ b/app/_layout.tsx @@ -67,6 +67,7 @@ const RootLayout = () => { + diff --git a/tests/components/not-found-screen.test.tsx b/tests/components/not-found-screen.test.tsx new file mode 100644 index 0000000..f2bdee7 --- /dev/null +++ b/tests/components/not-found-screen.test.tsx @@ -0,0 +1,26 @@ +import { render, screen, fireEvent } from "@testing-library/react-native"; + +const mockBack = jest.fn(); +jest.mock("expo-router", () => ({ + useRouter: () => ({ back: mockBack }), +})); + +import NotFoundScreen from "@/app/+not-found"; + +describe("NotFoundScreen", () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + + it("renders the not found message", () => { + render(); + expect(screen.getByText("Page not found")).toBeTruthy(); + expect(screen.getByText("The page you're looking for doesn't exist.")).toBeTruthy(); + }); + + it("navigates back when the button is pressed", () => { + render(); + fireEvent.press(screen.getByText("Go back")); + expect(mockBack).toHaveBeenCalled(); + }); +});