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:

Zoneless Change Detection In Angular 18

Zoneless change detection in Angular 18

Angular v18 introduced an experimental feature called zoneless change detection, eliminating the need for Zone.js.

Yan Sun
Jul 15, 2024 ⋅ 5 min read
Developing Cross Platform Apps With Bun Version 1.1

Developing cross-platform apps with Bun v1.1

For some years now, developers have faced many performance challenges while using traditional JavaScript runtimes like Node.js and Deno. Even […]

Clara Ekekenta
Jul 12, 2024 ⋅ 6 min read
Exploring The Magic Of Runes In Svelte 5

Exploring the magic of runes in Svelte 5

See how to use Svelte 5’s new runes system to declare reactive states and compare them to the existing approach to reactivity in Svelte 4.

Yashodhan Joshi
Jul 11, 2024 ⋅ 7 min read
Building UIs With Franken UI, A Shadcn Alternative

Building UIs with Franken UI, a Shadcn alternative

Explore Franken UI, an open source library of pre-built UI components that takes inspiration from Shadcn UI’s design principles.

Jude Miracle
Jul 10, 2024 ⋅ 11 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