Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest.mock() not working at all #32982

Closed
D-Pagey opened this issue Jan 4, 2022 · 4 comments
Closed

Jest.mock() not working at all #32982

D-Pagey opened this issue Jan 4, 2022 · 4 comments
Labels
SWC Related to minification/transpilation in Next.js.

Comments

@D-Pagey
Copy link
Contributor

D-Pagey commented Jan 4, 2022

What version of Next.js are you using?

latest

What version of Node.js are you using?

16.1.0

What browser are you using?

n/a

What operating system are you using?

macOS

How are you deploying your application?

n/a

Describe the Bug

I cloned https://github.com/vercel/next.js/tree/canary/examples/with-jest and simply added

// index.tsx
import Head from "next/head";
import Image from "next/image";
import axios from "axios";
import styles from "@/pages/index.module.css";

console.log({ axios });
index.test.tsx
import { render, screen } from "@testing-library/react";
import Home from "@/pages/index";

jest.mock("axios");

describe("Home", () => {
  it("renders a heading", () => {
    render(<Home />);

    const heading = screen.getByRole("heading", {
      name: /welcome to next\.js!/i,
    });

    expect(heading).toBeInTheDocument();
  });
});

Expected Behavior

Expect the console log to log a mocked axios but instead returns actual axios

To Reproduce

Add any jest.mock to anything in https://github.com/vercel/next.js/tree/canary/examples/with-jest

@D-Pagey D-Pagey added the bug Issue was opened via the bug report template. label Jan 4, 2022
@etiennejcharles
Copy link

Seems related to
swc-project/jest#14

@etiennejcharles
Copy link

Having the same issue right now, not able to do the switch to swc parser at the moment (sadly)

@balazsorban44 balazsorban44 added SWC Related to minification/transpilation in Next.js. kind: bug and removed bug Issue was opened via the bug report template. labels Jan 5, 2022
@balazsorban44
Copy link
Member

This actually seems to be a duplicate of #32539

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Feb 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
SWC Related to minification/transpilation in Next.js.
Projects
None yet
Development

No branches or pull requests

3 participants