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

It is not possible to mock non-existing files(?) #46

Closed
kennethlynne opened this issue Oct 14, 2018 · 4 comments
Closed

It is not possible to mock non-existing files(?) #46

kennethlynne opened this issue Oct 14, 2018 · 4 comments
Assignees

Comments

@kennethlynne
Copy link

I can not figure out why

rewiremock('../something').with({});
console.log(require('../something')); // module '../something' does not exit

does not work but

rewiremock('../existing').with({});
console.log(require('../existing')); // {}

does.

Is it possible to mock files that do not yet exist like for example mock-require does?

mockRequire('../something', {});
console.log(require('../something')); // {}
@theKashey
Copy link
Owner

It's possible, but I am actually planning to disable this possibility at all, to make life easier - not let you to make a mistake.

Is there any reason to import something non existing in your case?

@kennethlynne
Copy link
Author

I am unit testing a script that should require and execute some files based on a parameter.

Basically, tell a script that we want to do X, and the handler will require X.js and it will do something with that file, like call some methods etc.

So if you disable it by default I urge you to make it possible and easy to circumvent it.

But you say it is currently possible? I was not able to get it to work and I did not find the answer in the documentation, could you please provide an example?

@theKashey
Copy link
Owner

Rewiremock could mock everything, but it's a tricky thing to explain what to mock. Stuff like relative names may cause some issues.
Let me double check it.

@theKashey theKashey self-assigned this Oct 14, 2018
@theKashey
Copy link
Owner

So - it was not possible before :)

theKashey added a commit that referenced this issue Oct 17, 2018
Allow require non-existing files, fixes #46
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

2 participants