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

[Bug]: importing inside unstable_mockModule results in infinite loop #13851

Closed
jorislamers opened this issue Feb 2, 2023 · 4 comments
Closed

Comments

@jorislamers
Copy link

Version

29.4.1

Steps to reproduce

Using import inside unstable_mockModule results in an infinite loop (+heap out of memory error).

Using the example below but with unstable_mockModule results in an infinite loop

jest.mock('../myModule', () => {
  // Require the original module to not be mocked...
  const originalModule = jest.requireActual('../myModule');

  return {
    __esModule: true, // Use it when dealing with esModules
    ...originalModule,
    getRandom: jest.fn(() => 10),
  };
});

eg

jest.unstable_mockModule('../myModule', async () => {
  // Require the original module to not be mocked...
  const originalModule = await import('../myModule');

  return {
    ...originalModule,
    getRandom: jest.fn(() => 10),
  };
});

Should this work or is this not a valid use case?

Expected behavior

unstable_mockModule works the same as jest.mock and allows import inside moduleFactory to inject original module.

Actual behavior

Infinite loop

Additional context

No response

Environment

System:
    OS: Linux 6.0 Pop!_OS 22.04 LTS
    CPU: (12) x64 Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
  Binaries:
    Node: 14.21.2 - /usr/bin/node
    npm: 6.14.18 - /usr/bin/npm
@github-actions
Copy link

github-actions bot commented Mar 4, 2023

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Mar 4, 2023
@github-actions
Copy link

github-actions bot commented Apr 3, 2023

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 3, 2023
@github-actions
Copy link

github-actions bot commented Apr 3, 2023

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions
Copy link

github-actions bot commented May 4, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

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

No branches or pull requests

1 participant