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

[with-jest]: Update to use automatic path aliases #46982

Merged
merged 3 commits into from
Mar 13, 2023

Conversation

JohnDaly
Copy link
Contributor

Updating the with-jest example to make use of the automatic path alias feature that was added in #45815

I've also updated the dependencies in the example

@ijjk ijjk merged commit 97299a6 into vercel:canary Mar 13, 2023
@JohnDaly JohnDaly deleted the examples/update-with-jest branch March 13, 2023 17:20
@markmcdermid
Copy link

@JohnDaly thanks for the PR <3 - I'm trying to upgrade our test suite dependencies (a minefield) and this will be extremely helpful!

Unfortunately it doesn't look like this works for mocks, which would make it very hard for us to use (we'd still need to do some alias/path mapping in jest-config)

Adding the following to the Jest example:

components/MyComponent.tsx

export const MyComponent = () => <h1>Hi</h1>;

index.test.tsx

import { render, screen } from "@testing-library/react";
import Home from "@/pages/index";

jest.mock("@/components/MyComponent");

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

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

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

Results in: Cannot find module '@/components/MyComponent' from '__tests__/index.test.tsx'

Do you have any suggestions?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants