From 0275010041c238786deec9ab4a21fc011bec80a3 Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Fri, 6 Oct 2023 16:38:05 -0400 Subject: [PATCH] add subnav tests --- .eslintrc.js | 2 +- src/components/SubNav/SubNav.test.tsx | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/components/SubNav/SubNav.test.tsx diff --git a/.eslintrc.js b/.eslintrc.js index bf9cdd3ac..2eec7ffa6 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -3,7 +3,7 @@ module.exports = { browser: true, es2021: true, node: true, - jest: true + jest: true, }, extends: [ "next/core-web-vitals", diff --git a/src/components/SubNav/SubNav.test.tsx b/src/components/SubNav/SubNav.test.tsx new file mode 100644 index 000000000..efaee8b11 --- /dev/null +++ b/src/components/SubNav/SubNav.test.tsx @@ -0,0 +1,21 @@ +import React from "react" +import { render, screen, act } from "@testing-library/react" +import userEvent from "@testing-library/user-event" +import mockRouter from "next-router-mock" +// this import, as well as its use on line 15 is to avoid the following error: +// TypeError: Cannot use 'in' operator to search for 'beforePopState' in null +import { MemoryRouterProvider } from "next-router-mock/MemoryRouterProvider" + +import SubNav from "./SubNav" + +jest.mock("next/router", () => jest.requireActual("next-router-mock")) + +describe("SubNav", () => { + it("sends you to Subject Heading Explorer", async () => { + render(, { + wrapper: MemoryRouterProvider, + }) + const subNavLinks = screen.getAllByRole("link") + expect(subNavLinks).toHaveLength(3) + }) +})