2024-03-14
2475
#nextjs
Atharva Deosthale
100874
Mar 14, 2024 ⋅ 8 min read

Testing Next.js apps with Jest

Atharva Deosthale Web Developer and Designer | JavaScript = ❤ | MERN Stack Developer

Recent posts:

Building a Full-Featured Laravel Admin Dashboard with Filament

Building a full-featured Laravel admin dashboard with Filament

Build scalable admin dashboards with Filament and Laravel using Form Builder, Notifications, and Actions for clean, interactive panels.

Kayode Adeniyi
Dec 20, 2024 ⋅ 5 min read
Working With URLs In JavaScript

Working with URLs in JavaScript

Break down the parts of a URL and explore APIs for working with them in JavaScript, parsing them, building query strings, checking their validity, etc.

Joe Attardi
Dec 19, 2024 ⋅ 6 min read
Lazy Loading Vs. Eager Loading

Lazy loading vs. Eager loading

In this guide, explore lazy loading and error loading as two techniques for fetching data in React apps.

Njong Emy
Dec 18, 2024 ⋅ 5 min read
Deno logo over an orange background

How to migrate your Node.js app to Deno 2.0

Deno is a popular JavaScript runtime, and it recently launched version 2.0 with several new features, bug fixes, and improvements […]

Yashodhan Joshi
Dec 17, 2024 ⋅ 7 min read
View all posts

8 Replies to "Testing Next.js apps with Jest"

  1. Below error occured,

    Cannot find module ‘react-dom/client’ from ‘node_modules/@testing-library/react/dist/pure.js’

    1. Hey Somnath! This error might have been caused because of your packages not being properly installed. Please delete the “node_modules” folder and run “npm install” again. Make sure you’re importing functions and components from the correct package.

  2. hey, the second test is failed:
    ` it(“adds numbers”, () => {
    render()
    // check if adds properly
    const num1input = screen.getByTestId(“num1”)
    const num2input = screen.getByTestId(“num2”)
    const addButton = screen.getByTestId(“add”)
    const resultArea = screen.getByTestId(“result”)
    fireEvent.change(num1input, { target: { value: 5 } })
    fireEvent.change(num2input, { target: { value: 8 } })
    addButton.click()
    expect(resultArea).toHaveTextContent(“13”)
    })`

    Expected element to have text content:
    13
    Received:
    0

  3. This if for a Next.js Project. It said “As of Jest 28 “jest-environment-jsdom” is no longer shipped by default, make sure to install it separately.” So I did “npm install –save-dev jest-environment-jsdom” and I’ve removed the line “testEnvironment: “jest-environment-jsdom”,” from the “jest.config.js” file. Then it works..!

Leave a Reply