Skip to content

Feature Request: Module level mocking #51164

@jasonwilliams

Description

@jasonwilliams

What is the problem this feature will solve?

Currently you can't mock external or built-in modules which makes it difficult if you code imports a module that may run some side-effects and you have no control over it.

There may be some built in modules which you need to stub out but don't have access to during a test run.

What is the feature you are proposing to solve the problem?

Allowing us to use the built-in test runner to mock modules entirely.

There has already been some work in this by @cjihrig

I think the biggest things missing before I can open a PR are related to ESM loaders and are tracked in #49472 and #49473.

Both of those issues look to be resolved now, I don't know what the current blockers are for this

What alternatives have you considered?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.test_runnerIssues and PRs related to the test runner subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions