Skip to content

expect is not defined #606

@Boby900

Description

@Boby900
  • @testing-library/jest-dom version: ^6.4.6
  • node version: v21.1.0
  • jest (or vitest) version: ^29.7.0
  • npm (or yarn) version: 10.4.0
  • react-testing-library version: ^16.0.0

Relevant code or config:

//__tests__index.test.js
import '@testing-library/jest-dom'
import { render, screen } from '@testing-library/react'
import ProfileForm from '@/components/Form'
import { expect } from '@jest/globals';
import '@testing-library/jest-dom/extend-expect'; // for additional matchers

describe('Home', () => {
  it('renders a heading', () => {
    render(<ProfileForm />)
 
    const heading = screen.getByRole('heading', { level: 1 })
 
    expect(heading).toBeInTheDocument()
  })
})

// jest.setup.ts
import { config } from 'dotenv';
config();
import '@testing-library/jest-dom';

//jest.config.ts
import nextJest from "next/jest.js";
import type { Config } from "jest";
const createJestConfig = nextJest({
  dir: "./",
});
const config: Config = {
  clearMocks: true,
  moduleNameMapper: {
    "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
      "<rootDir>/__mocks__/fileMock.js",
    "\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js",
  },
  collectCoverage: true,
  coverageDirectory: "coverage",
  coverageProvider: "v8",
  preset: "ts-jest",
  testEnvironment: "node",
  setupFiles: ["<rootDir>/jest.setup.ts"],
  transform: {
    "^.+\\.tsx?$": "ts-jest",
  },
};
export default createJestConfig(config);

What you did:

I was just trying to run my test and I was using expect

What happened:

my test is not running and it's showing that expect is not defined

Reproduction:

https://github.com/Boby900/yogurt

Problem description:

I am not able to run my test

Screenshot (555)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions