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

Simulate the absence of a module #119

Open
j-ulrich opened this issue Sep 3, 2020 · 0 comments
Open

Simulate the absence of a module #119

j-ulrich opened this issue Sep 3, 2020 · 0 comments

Comments

@j-ulrich
Copy link

j-ulrich commented Sep 3, 2020

Is it possible to simulate the absence of a module with rewiremock? Meaning: make the require() call throw a MODULE_NOT_FOUND exception?

proxyquire supports this by simply setting the dependency to null in the configuration.

I also tried this using rewiremock like this:

const myModuleWithMocks = rewiremock.proxy( 'myModule.js', {
   'dependency':  null
 } );

I also tried using .with() and .by(). I also tried using a function which throws an exception but nothing makes the require() throw. When setting the dependency to null, then the require() call simply returns null as well.

My use case is that I have an optional dependency and I want to test the fallback code which handles the case that the dependency is not available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant