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:

Rxjs Adoption Guide: Overview, Examples, And Alternatives

RxJS adoption guide: Overview, examples, and alternatives

Get to know RxJS features, benefits, and more to help you understand what it is, how it works, and why you should use it.

Emmanuel Odioko
Jul 26, 2024 ⋅ 13 min read
Decoupling Monoliths Into Microservices With Feature Flags

Decoupling monoliths into microservices with feature flags

Explore how to effectively break down a monolithic application into microservices using feature flags and Flagsmith.

Kayode Adeniyi
Jul 25, 2024 ⋅ 10 min read
Lots of multi-colored blue and purplish rectangles.

Animating dialog and popover elements with CSS @starting-style

Native dialog and popover elements have their own well-defined roles in modern-day frontend web development. Dialog elements are known to […]

Rahul Chhodde
Jul 24, 2024 ⋅ 10 min read
Using Llama Index To Add Personal Data To Large Language Models

Using LlamaIndex to add personal data to LLMs

LlamaIndex provides tools for ingesting, processing, and implementing complex query workflows that combine data access with LLM prompting.

Ukeje Goodness
Jul 23, 2024 ⋅ 5 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