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

Mocking external module import #148

Open
Subham-dury opened this issue Mar 5, 2024 · 2 comments
Open

Mocking external module import #148

Subham-dury opened this issue Mar 5, 2024 · 2 comments

Comments

@Subham-dury
Copy link

Hi,
I am using rewiremock for the first time in my project. There is a dependency on mysql in my project for pool creation and execution of a query. I have an import statement of :

import mysql from 'mysql2/promise' ;
....
mysql.createPool(conectionConfiguration);

In my test class how can I go about creating mock for the mysql import so that I can control the flow of code and execution of query.
I tried to use rewiremock.enable() ; But got error prompt: Not a function..something like that.

Note : My main code is in .mjs extension.
Error img :
image

@theKashey
Copy link
Owner

if rewiremock.enable is not a function, then what is rewiremock?

@danyalaytekin
Copy link

danyalaytekin commented Mar 20, 2024

My main code is in .mjs extension

@Subham-dury How about your test code? I was encountering this in a test suite, read the docs again, realised I had to switch to require('rewiremock/node'), and now it's gone. There are a few other alternatives in the docs as well.

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

3 participants